List of usage examples for java.util Calendar set
public final void set(int year, int month, int date)
YEAR
, MONTH
, and DAY_OF_MONTH
. From source file:Main.java
public static long getTimeLongTenHours(int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); calendar.set(Calendar.HOUR_OF_DAY, 10); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Date beginOfTheDay(@NonNull Date date) { Calendar inputDate = Calendar.getInstance(); inputDate.setTime(date);//from w w w.j av a2 s.co m Calendar resultDate = Calendar.getInstance(); resultDate.set(inputDate.get(Calendar.YEAR), inputDate.get(Calendar.MONTH), inputDate.get(Calendar.DAY_OF_YEAR)); return resultDate.getTime(); }
From source file:Main.java
public static java.util.Date getDateFromDatePicker(DatePicker datePicker) { int day = datePicker.getDayOfMonth(); int month = datePicker.getMonth(); int year = datePicker.getYear(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); return calendar.getTime(); }
From source file:Main.java
public static long getDate(int year, int monthOfYear, int dayOfMonth) { Calendar c = Calendar.getInstance(); c.set(year, monthOfYear, dayOfMonth); return c.getTimeInMillis(); }
From source file:Main.java
@SuppressWarnings({ "static-access" }) public static String getFutureMonthDay(String iFuntureMonth, String sBirthDay) { if (!"".equals(iFuntureMonth) && !"".equals(sBirthDay)) { Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(sBirthDay.substring(0, 4)), Integer.parseInt(sBirthDay.substring(5, 7)) - 1, Integer.parseInt(sBirthDay.substring(8, 10))); cal.add(cal.MONTH, Integer.parseInt(iFuntureMonth)); return cal.get(cal.YEAR) + "/" + String.format("%02d", (cal.get(cal.MONTH) + 1)) + "/" + String.format("%02d", cal.get(cal.DATE)); } else {/*from w ww . j a v a2 s . co m*/ return ""; } }
From source file:Main.java
private static long beginningOfTheDay(Calendar time) { Calendar copy = (Calendar) time.clone(); copy.clear();// w ww . j a va 2s . c o m copy.set(time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH)); return copy.getTimeInMillis(); }
From source file:Main.java
public static int getWeekOfYear(String year, String month, String day) { Calendar cal = new GregorianCalendar(); cal.clear();/* w w w .ja va 2 s. c o m*/ cal.set(new Integer(year).intValue(), new Integer(month).intValue() - 1, new Integer(day).intValue()); return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:Main.java
public static List<Integer> getAllDayInMonth(int month, int year) { List<Integer> listDate = new ArrayList<Integer>(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, 1); calendar.clear(Calendar.HOUR); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); for (int i = 1; i <= totalDays; i++) { listDate.add(i);/* ww w .java2 s .co m*/ } return listDate; }
From source file:Main.java
public static boolean isInFuture(int day, int month, int year) { Calendar c = Calendar.getInstance(); c.set(year, month - 1, day); Date futureDate = c.getTime(); return (futureDate.getTime() > new Date().getTime()); }
From source file:Main.java
public static int getAge(String year, String month, String day) throws NumberFormatException { int yearInt = Integer.parseInt(year); int monthInt = Integer.parseInt(month); int dayInt = Integer.parseInt(day); monthInt--;/*from w ww .ja v a 2 s . c o m*/ Calendar birthCal = Calendar.getInstance(); birthCal.set(yearInt, monthInt, dayInt); Calendar todayCal = Calendar.getInstance(); int diff = todayCal.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); if (birthCal.get(Calendar.MONTH) > todayCal.get(Calendar.MONTH) || (birthCal.get(Calendar.MONTH) == todayCal.get(Calendar.MONTH) && birthCal.get(Calendar.DATE) > todayCal.get(Calendar.DATE))) { diff--; } return diff; }