Java Utililty Methods Calendar Hour

List of utility methods to do Calendar Hour

Description

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

Method

longelapsedHours(Calendar aFirstDate, Calendar aSecondDate)
elapsed Hours
return Math.abs(millisToHours(aSecondDate.getTimeInMillis() - aFirstDate.getTimeInMillis()));
Integerget24Hour(Calendar calendar)
get Hour
Integer hour = calendar.get(Calendar.HOUR_OF_DAY);
return hour;
intgetHour(boolean twentyFour, Calendar calendar)
get Hour
return calendar.get(twentyFour ? Calendar.HOUR_OF_DAY : Calendar.HOUR);
intgetHour(Calendar cal)
get Hour
int hr = cal.get(Calendar.HOUR);
return (hr == 0 ? 12 : hr);
StringgetHour(Calendar cal)
get Hour
return strLen(String.valueOf(cal.get(Calendar.HOUR_OF_DAY)), 2);
intgetHour(Calendar calendar)
get Hour
return calendar.get(Calendar.HOUR_OF_DAY);
inthour(Calendar calendar)
hour
return calendar.get(Calendar.HOUR_OF_DAY);
voidhourFloor(Calendar calendar)
hour Floor
minuteFloor(calendar);
calendar.set(Calendar.MINUTE, 0);
inthoursInDay(Calendar cal)
This function returns number of hour in a day when given a Calendar with appropriate TZ.
Calendar localCal = new GregorianCalendar(cal.getTimeZone());
localCal.set(Calendar.MILLISECOND, 0);
localCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 30, 0);
localCal.add(Calendar.HOUR_OF_DAY, 24);
switch (localCal.get(Calendar.HOUR_OF_DAY)) {
case 1:
    return 23;
case 23:
...
CalendarmoveHoursHand(int aNumberOfHours, Calendar aCalendar)
move Hours Hand
Calendar clone = clone(aCalendar);
clone.add(Calendar.HOUR_OF_DAY, aNumberOfHours);
return clone;