Java Utililty Methods Calendar Millisecond

List of utility methods to do Calendar Millisecond

Description

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

Method

Calendarcalendar(long millis)
calendar
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millis);
return calendar;
longcalendarToGMTMillis(Calendar cal)
Convert a calendar object to a long in the form of milliseconds since the epoch of January 1, 1970.
Date date = cal.getTime();
long time = date.getTime();
return time;
longcalendarToGMTMillis(Calendar cal)
Convert a calendar object to a long in the form of milliseconds since the epoch of January 1, 1970.
Date date = cal.getTime();
TimeZone tz = cal.getTimeZone();
int offset = tz.getOffset(date.getTime());
long time;
if (offset != 0) {
    Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    gmtCal.setTime(date);
    gmtCal.add(Calendar.MILLISECOND, offset);
...
voidclearCalendarMillisecond(Calendar cal)
clear Calendar Millisecond
cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
longelapsedMillis(Calendar before, Calendar after)
Retrieve the amount of elapsed milliseconds between the two given calendars.
return elapsedMillis(before, after, 1); 
CalendargetCalendarXDaysFromY(long startTimeInMillis, int daysFromStartDate)
get Calendar X Days From Y
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(startTimeInMillis);
cal.add(Calendar.DAY_OF_YEAR, daysFromStartDate);
return cal;
longgetDateMilliseconds(Calendar pDate)
get Date Milliseconds
return pDate.getTimeInMillis();
CalendargetLastMilli(Calendar cal)
Returns the last millisecond of the given day the day (2008/03/07 15:23:32 992ms --> 2008/03/07 23:59:59 999ms)
Calendar ret = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
        cal.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
ret.set(Calendar.MILLISECOND, 999);
return ret;
intgetMillisecond(Calendar calendar)
get Millisecond
return calendar.get(Calendar.MILLISECOND);
intgetMilliSinceMidnight(Calendar arg)
gets the number of milliseconds since Midnight of the current day (UTC) of the argument
int millis = arg.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000;
millis = millis + arg.get(Calendar.MINUTE) * 60 * 1000;
millis = millis + arg.get(Calendar.SECOND) * 1000;
millis = millis + arg.get(Calendar.MILLISECOND);
return millis;