Java Utililty Methods Calendar Time

List of utility methods to do Calendar Time

Description

The list of methods to do Calendar Time are organized into topic(s).

Method

int[]getTime(Calendar c)
Return day's year, month(1-12), day(1-31), week(0-6, for SUN, MON, ...
int week = c.get(Calendar.DAY_OF_WEEK) - 1;
if (week == 0)
    week = 7;
return new int[] { c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH), week,
        c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND) };
StringgetTime(Calendar cal)
get Time
String Time = "00:00";
int min = getMinutes(cal);
Time = getHour(cal) + ":";
Time = Time + (min < 10 ? ("0" + min) : min) + " " + getAM_PM(cal);
return Time;
DategetTime(Date date, int CalendarType, int interval)
get Time
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(CalendarType, interval);
return c.getTime();
VectorgetTimeFrame(final Calendar calFrom, final Calendar calTo)
get Time Frame
assert calFrom != null : "'calFrom' can't be null";
assert calTo != null : "'calTo' can't be null";
int from = calendarToInt(calFrom);
int to = calendarToInt(calTo);
return getTimeFrame(from, to);
StringgetTimeInHHMMSS(Calendar time)
get Time In HHMMSS
if (time == null)
    return "HH:MM";
int h = time.get(Calendar.HOUR_OF_DAY);
int m = time.get(Calendar.MINUTE);
StringBuilder sb = new StringBuilder();
if (h < 10)
    sb.append("0");
sb.append(h).append(":");
...
StringgetTimeStr(Calendar cal)
get Time Str
return getHour(cal) + ":" + getMinute(cal);
StringgetTimeToString(Calendar argCal)
Return [HH]h[mm]
Calendar cal = argCal;
if (cal == null) {
    cal = new GregorianCalendar();
String date = "";
if (cal.get(Calendar.HOUR_OF_DAY) < 10) {
    date += "0";
date += cal.get(Calendar.HOUR_OF_DAY) + TIME_SEPARATOR;
if (cal.get(Calendar.MINUTE) < 10) {
    date += "0";
date += cal.get(Calendar.MINUTE);
return date;
longgetTimeValue(Calendar cal)
Returns a number based on the date and time of the specified Calendar object.
if (cal == null) {
    cal = Calendar.getInstance();
return cal.getTimeInMillis();
intgetTimeYYYYMMDD(Calendar calendar)
get Time YYYYMMDD
return 10000 * calendar.get(Calendar.YEAR) + (calendar.get(Calendar.MONTH) + 1) * 100
        + calendar.get(Calendar.DAY_OF_MONTH);
TimeZonegetTimeZone(Calendar cal)
Gets the active time zone based on a Calendar argument
if (cal == null) {
    return DEFAULT_ZONE;
return cal.getTimeZone();