List of utility methods to do Calendar Create
Calendar | createCalendar(int year, int month, int day) create Calendar Calendar dateTime = Calendar.getInstance();
dateTime.clear();
dateTime.set(year, month, day);
return dateTime;
|
Calendar | createCalendar(int year, int month, int day, int hour, int minute, int second, boolean ceiling) Creates a calendar in the given year. Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.set(Calendar.YEAR, year);
fillInField(Calendar.MONTH, month - 1, ceiling, cal);
fillInField(Calendar.DAY_OF_MONTH, day, ceiling, cal);
fillInField(Calendar.HOUR_OF_DAY, hour, ceiling, cal);
fillInField(Calendar.MINUTE, minute, ceiling, cal);
fillInField(Calendar.SECOND, second, ceiling, cal);
fillInField(Calendar.MILLISECOND, -1, ceiling, cal);
...
|
Calendar | createCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) create Calendar return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second); |
Calendar | createCalendar(long timeInMillis) create Calendar Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeInMillis);
calendar.setMinimalDaysInFirstWeek(calculateMinimalDaysInFirstWeek(calendar));
return calendar;
|
Calendar | createCalendarFromParts(String[] parts) create Calendar From Parts Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getDefault()); calendar.set(Calendar.YEAR, Integer.parseInt(parts[YEAR])); calendar.set(Calendar.MONTH, Integer.parseInt(parts[MONTH]) - 1); calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parts[DAY])); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[HOUR])); calendar.set(Calendar.MINUTE, Integer.parseInt(parts[MINUTE])); calendar.set(Calendar.SECOND, 0); ... |
Calendar | createCalendarInstance(final Locale locale) Create a calendar instance that uses mondays or sundays as the first day of the week depending on the given locale and sets the week number 1 to the first week in the year that has four days of january. final Calendar cal = Calendar.getInstance(locale); cal.setMinimalDaysInFirstWeek(4); return cal; |
Calendar | createCalendarMidnight(final Date date) Creates a calendar with hour, minute, second, millisecond set to zero for given Date. Calendar cal = new GregorianCalendar(getTimeZone("GMT+0")); cal.setTime(date); cal.set(HOUR_OF_DAY, 0); cal.set(MINUTE, 0); cal.set(SECOND, 0); cal.set(MILLISECOND, 0); return cal; |
Calendar | createCalendarWith() create Calendar With final Calendar cal = Calendar.getInstance(tz); return cal; |
StringBuilder | createDateFormatString(Calendar cal) create Date Format String String postfix = getDayOfMonthPostfix(cal); StringBuilder builder = new StringBuilder(); builder.append("d'").append(postfix).append(" of' MMMM yyyy '@' HH:mm zzz"); return builder; |
String | createDateStr(Calendar calendar) create Date Str int monthInt = calendar.get(Calendar.MONTH) + 1; String monthStr = monthInt < 10 ? "0" + monthInt : "" + monthInt; int dayInt = calendar.get(Calendar.DAY_OF_MONTH); String dayStr = dayInt < 10 ? "0" + dayInt : "" + dayInt; String dateStr = calendar.get(Calendar.YEAR) + DATE_DELIMITER + monthStr + DATE_DELIMITER + dayStr; return dateStr; |