List of utility methods to do Calendar Create
Calendar | getCalendarAtMidnight(Date d) Set the given date to a Calendar at midnight. Calendar cal = date2Calendar(d);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
|
Calendar | getCalendarBefore(int i) get Calendar Before return getCalendarBefore(Calendar.getInstance(), i);
|
Calendar | getCalendarByName(String timeZone) get Calendar By Name timeZone = timeZone.trim(); TimeZone zone = TimeZone.getTimeZone(timeZone); String id = zone.getID(); if (id.compareTo(timeZone) != 0) { throw new IllegalArgumentException("Bad timezone name: '" + timeZone + "'"); return Calendar.getInstance(zone); |
Calendar | getCalendarBySpecific(int year, int month, int date, int hour) get Calendar By Specific Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, date); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); ... |
Calendar | getCalendarByValue(String timeZone) get Calendar By Value timeZone = timeZone.trim(); char ch = timeZone.charAt(0); if (ch == '+' || ch == '-') { timeZone = "GMT" + timeZone; } else if (Character.getType(ch) == Character.DECIMAL_DIGIT_NUMBER) { timeZone = "GMT+" + timeZone; String prefix = timeZone.substring(0, 4); ... |
Calendar | getCalendarDate() Retrieve Calendar date. final Calendar currentDate = Calendar.getInstance(); currentDate.set(Calendar.SECOND, 0); return currentDate; |
String | getCalendarDate(Calendar calendar) get Calendar Date String year = String.valueOf(calendar.get(Calendar.YEAR)); String month = String.valueOf(calendar.get(Calendar.MONTH) + 1); if (month.length() < 2) month = "0" + month; String date = String.valueOf(calendar.get(Calendar.DATE)); if (date.length() < 2) date = "0" + date; String hours = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)); ... |
long | getCalendarDateFromToday(final int numDays) Flips through the Calendar from the current date over the given number of days to fetch the required date in milli seconds. Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DAY_OF_MONTH, numDays); return cal.getTimeInMillis(); |
String | getCalendarDayString(Calendar date) returns the month (mm) as a string from a calendar date return String.valueOf(date.get(Calendar.DAY_OF_MONTH));
|
int | getCalendarField(char c) get Calendar Field switch (c) { case 'y': return Calendar.YEAR; case 'M': return Calendar.MONTH; case 'D': return Calendar.DAY_OF_YEAR; case 'd': ... |