Java Utililty Methods Hour

List of utility methods to do Hour

Description

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

Method

IntegerconvertHour(Long createAt)
convert Hour
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(createAt);
return cal.get(Calendar.HOUR);
longdelayBeforeNextHour()
delay Before Next Hour
return nextHour().getTime() - System.currentTimeMillis();
intget24Hour()
get Hour
return calendar.get(Calendar.HOUR_OF_DAY);
longgetAlarmOnQuarterHour()
Setup to find out when the quarter-hour changes (e.g.
Calendar nextQuarter = Calendar.getInstance();
nextQuarter.set(Calendar.SECOND, 1);
nextQuarter.set(Calendar.MILLISECOND, 0);
int minute = nextQuarter.get(Calendar.MINUTE);
nextQuarter.add(Calendar.MINUTE, 15 - (minute % 15));
long alarmOnQuarterHour = nextQuarter.getTimeInMillis();
long now = System.currentTimeMillis();
long delta = alarmOnQuarterHour - now;
...
CalendargetAnHourBack()
get An Hour Back
return getAnHourBack(new Date());
StringgetBeforeOneHour()
get Before One Hour
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
return String.valueOf(cal.get(Calendar.HOUR_OF_DAY) == 0 ? 23 : cal.get(Calendar.HOUR_OF_DAY) - 1);
CalendargetCalenderWithHour(int hours)
get Calender With Hour
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.add(Calendar.HOUR, hours);
return cal;
StringgetCurrentHour()
get Current Hour
Calendar calendar;
calendar = new GregorianCalendar();
String hour = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
return hour;
DategetCurrentHour()
get Current Hour
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
floatgetCurrentHour()
get Current Hour
Calendar cal = Calendar.getInstance();
return cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) / 60f;