List of utility methods to do Calendar Create
Integer | getCalendarField(Date date, int calFieldId) Shortcut function that returns the given Calendar field for the date if (date != null) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(calFieldId); return null; |
String | getCalendarFieldName(int field) get Calendar Field Name switch (field) { case Calendar.DAY_OF_MONTH: return "DAY_OF_MONTH"; case Calendar.DAY_OF_WEEK: return "DAY_OF_WEEK"; case Calendar.DAY_OF_YEAR: return "DAY_OF_YEAR"; case Calendar.HOUR: ... |
Calendar | getCalendarFormYear(int year) get Calendar of given year Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
cal.set(Calendar.YEAR, year);
return cal;
|
GregorianCalendar | getCalendarForNextRun(GregorianCalendar startTime, int targetDay, int targetHour) Given a start time, computes the next time when the wallclock will reach a certain hour of the day, on a certain day of the week Eg: From today, when is the next Saturday, 12PM ? long startTimeMs = startTime.getTimeInMillis(); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(startTimeMs); cal.set(Calendar.HOUR_OF_DAY, targetHour); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); if (cal.get(Calendar.DAY_OF_WEEK) != targetDay || cal.getTimeInMillis() < startTimeMs) { ... |
Calendar | getCalendarForSchedule(Calendar cal) get Calendar For Schedule return cal;
|
Calendar | getCalendarForTime(final long timeInMilliseconds) Function to return a calendar object holding the UTC representation of the current time. Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(timeInMilliseconds); return calendar; |
Calendar | getCalendarFromDates(Date date, Date hourMinuteMillisseconds) Merge two Date variables to compose a single Calendar object. Calendar ret = Calendar.getInstance(); ret.setTime(date); Calendar hour = Calendar.getInstance(); hour.setTime(hourMinuteMillisseconds); ret.set(Calendar.HOUR_OF_DAY, hour.get(Calendar.HOUR_OF_DAY)); ret.set(Calendar.MINUTE, hour.get(Calendar.MINUTE)); ret.set(Calendar.SECOND, hour.get(Calendar.SECOND)); ret.set(Calendar.MILLISECOND, hour.get(Calendar.MILLISECOND)); ... |
Calendar | getCalendarFromSystemTimeInMillis(long date) get Calendar From System Time In Millis Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date); return calendar; |
Calendar | getCalendarGMT() get Calendar GMT Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT")); return c; |
Calendar | getCalendarInstance() Get a new calendar instance from UTC timezone return Calendar.getInstance(UTC_TIMEZONE);
|