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

StringgetHourMinuteString(Date t)
get Hour Minute String
c1.setTime(t);
String hour = c1.get(Calendar.HOUR_OF_DAY) < 10 ? "0" + c1.get(Calendar.HOUR_OF_DAY)
        : Integer.toString(c1.get(Calendar.HOUR_OF_DAY));
String minute = c1.get(Calendar.MINUTE) < 10 ? "0" + c1.get(Calendar.MINUTE)
        : Integer.toString(c1.get(Calendar.MINUTE));
return hour + ":" + minute;
StringgetHourOfDay(Calendar date)
gets the hour-of-day of the given date
String hourOfDay = HOUR_FORMATTER.format(date.get(Calendar.HOUR_OF_DAY));
return hourOfDay;
intgetHourOfDay(final Date date)
Get the hour of the day by given date.
return getNumberOfGranularity(Calendar.HOUR_OF_DAY, date);
intgetHourOfDayInAm(Date dt)
Returns an hour in AM
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
int hour = cal.get(Calendar.HOUR_OF_DAY);
if (hour > 12) {
    hour = hour - 12;
return hour;
intgetHourOfWeek(Date dateIn)
Returns the hour of the week in the range of 1 to 168.
if (dateIn == null) {
    throw new IllegalArgumentException("Can not operate on a null Date object.");
Calendar cal = Calendar.getInstance();
cal.setTime(dateIn);
return ((cal.get(Calendar.DAY_OF_WEEK) - 1) * 24) + cal.get(Calendar.HOUR_OF_DAY);
intgetHours()
get Hours
Calendar now = Calendar.getInstance();
return now.get(Calendar.HOUR);
intgetHours()
get Hours
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
intgetHours(Date t, Date baseDate)
Get hours difference between two dates
Calendar cal = Calendar.getInstance();
cal.setTime(baseDate);
long sl = cal.getTimeInMillis();
long el, delta;
cal.setTime(t);
el = cal.getTimeInMillis();
delta = el - sl;
int value = (int) (delta / (60 * 60 * 1000));
...
intgetHours(final Date date)
The Method from the Date.getHours is deprecated.
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.HOUR_OF_DAY);
intgetHours(java.util.Date _date)
get Hours
Calendar calendar = Calendar.getInstance();
calendar.setTime(_date);
int value = calendar.get(Calendar.HOUR);
calendar.clear();
return value;