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

intcalendar2TimeStamp(Calendar cal)
calendar Time Stamp
return (int) (cal.getTimeInMillis() / 1000L);
CalendarcalendarFromString(String dateString, String timeString)
Returns calendar instance created from given date string.
if (dateString.length() < 10)
    return null;
if (timeString.length() < 8)
    return null;
GregorianCalendar cal = new GregorianCalendar();
try {
    int day = Integer.parseInt(dateString.substring(0, 2));
    int month = Integer.parseInt(dateString.substring(3, 5));
...
longcalendarToGPSTime(Calendar calendar)
Takes a date string of the form dd-mm-yyyy hh:mm:ss and converts it into a GPS time representing the number of seconds since 01-06-1980 00:00:00.
return calendar.getTimeInMillis() / 1000L - GPS_UNIX_EPOCH_OFFSET;
CalendarceilTime(Calendar calendar)
Returns a new Calendar with the same date of given calendar but with all time fields setted to their max value ( Calendar#HOUR_OF_DAY to 23, Calendar#MINUTE to 59, Calendar#SECOND to 59, Calendar#MILLISECOND to 999).
if (calendar != null) {
    Calendar c = (Calendar) calendar.clone();
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
    return c;
return calendar;
voidclearCalendarTime(Calendar cal)
Clears the time portion of the specified Calendar , setting the hour, minute, second, and millisecond parts to 0.
if (cal == null) {
    throw new IllegalArgumentException("The calendar must be defined.");
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
voidclearCalendarTimeParts(Calendar cal)
clear Calendar Time Parts
cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
clearCalendarMinuteWithRear(cal);
voidclearTime(Calendar c)
clear Time
c.set(Calendar.HOUR_OF_DAY, 10);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
voidclearTime(Calendar cal)
clear Time
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
voidclearTime(Calendar cal)
Clears the time component on a Calendar object.
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
voidclearTime(Calendar calendar)
clear Time
calendar.clear(Calendar.HOUR);
calendar.clear(Calendar.HOUR_OF_DAY);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
calendar.clear(Calendar.AM_PM);