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

voidclearTime(final Calendar c)
Set Calendar#HOUR_OF_DAY , Calendar#MINUTE , Calendar#SECOND and Calendar#MILLISECOND to 0.
if (c != null) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
voidclearTimeFields(final Calendar calendar)
Clears all the time fields in Calendar object.
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
voidclearTimeFields(Set c)
Clears the date fields on the specified calendar collection.
for (Calendar cal : c) {
    clearTimeFields(cal);
CalendarclearTimeFromCalendar(Calendar calendar)
clear Time From Calendar
if (calendar != null) {
    calendar.set(Calendar.HOUR, 0);
    calendar.clear(Calendar.AM_PM); 
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.clear(Calendar.DST_OFFSET);
...
intcompareTimeOnly(Calendar cal1, Calendar cal2)
compare Time Only
cal2.set(Calendar.YEAR, cal1.get(Calendar.YEAR));
cal2.set(Calendar.MONTH, cal1.get(Calendar.MONTH));
cal2.set(Calendar.DATE, cal1.get(Calendar.DATE));
return cal1.compareTo(cal2);
CalendarconvertCalendar(final Calendar calendar, final TimeZone timeZone)
Adapt calendar to client time zone.
Calendar ret = new GregorianCalendar(timeZone);
ret.setTimeInMillis(calendar.getTimeInMillis() + timeZone.getOffset(calendar.getTimeInMillis())
        - TimeZone.getDefault().getOffset(calendar.getTimeInMillis()));
ret.getTime();
return ret;
longconvertTimeToLocalTimezone(Long pTime, Calendar pTargetCal)
convert Time To Local Timezone
gmtCalendar.setTimeInMillis(pTime);
pTargetCal.set(Calendar.YEAR, gmtCalendar.get(Calendar.YEAR));
pTargetCal.set(Calendar.MONTH, gmtCalendar.get(Calendar.MONTH));
pTargetCal.set(Calendar.DAY_OF_MONTH, gmtCalendar.get(Calendar.DAY_OF_MONTH));
pTargetCal.set(Calendar.HOUR_OF_DAY, gmtCalendar.get(Calendar.HOUR_OF_DAY));
pTargetCal.set(Calendar.MINUTE, gmtCalendar.get(Calendar.MINUTE));
pTargetCal.set(Calendar.SECOND, gmtCalendar.get(Calendar.SECOND));
pTargetCal.set(Calendar.MILLISECOND, gmtCalendar.get(Calendar.MILLISECOND));
...
StringconvertTimeToString(Calendar time)
Converts time as Calendar in the string format 'hh:mm:ss'.
String timeText = "";
int hour = time.get(Calendar.HOUR_OF_DAY);
if (hour < 10) {
    timeText += "0";
timeText += hour + ":";
int minute = time.get(Calendar.MINUTE);
if (minute < 10) {
...
longconvertToActiveDirectoryTime(Calendar calendar)
Converts the given calendar to the equivalent Active Directory time.
return ((calendar.getTime().getTime() * 10000L) + 116444736000000000L);
CalendarconvertToCalendar(long adTimeValue)
Converts the given Active Directory time value to an equivalent calendar.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((adTimeValue - 116444736000000000L) / 10000L);
return calendar;