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

StringgetHourAndMinutes(Date dt)
Get and return the hours and minutes from the given Date dt, ex: 11:30
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
return (cal.get(Calendar.HOUR) + ":" + (cal.get(Calendar.MINUTE)));
DategetHourBeforeTime(int hour)
get Hour Before Time
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY) - hour);
return now.getTime();
CalendargetHourByZore(int hour)
get Hour By Zore
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.HOUR_OF_DAY, hour);
return c;
StringgetHourDetails(int timeInfo)
get Hour Details
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.HOUR_OF_DAY, timeInfo);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy HH:MM");
return formatter.format(cal.getTime());
StringgetHourFormatedTwoDigit()
get Hour Formated Two Digit
return intTwoDigit(getHour());
IntegergetHourFromDate(Date date)
get Hour From Date
Integer result = null;
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    result = calendar.get(Calendar.HOUR);
return result;
intgetHourInt()
get Hour Int
Calendar ca = Calendar.getInstance();
ca.setTime(new Date());
return ca.get(Calendar.HOUR_OF_DAY);
StringgetHourMin(Date date)
get Hour Min
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String ohHour = cal.get(Calendar.HOUR_OF_DAY) + "";
String ohMinute = cal.get(Calendar.MINUTE) + "";
if (ohMinute.length() == 1) {
    ohMinute = "0" + ohMinute;
if (ohHour.length() == 1) {
...
StringgetHourMinuteSecondByMisSecond(long misSecond)
get Hour Minute Second By Mis Second
if (misSecond < 0) {
    throw new IllegalArgumentException("The misSecond must not be negative");
if (misSecond == 0) {
    return "--";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(misSecond);
...
StringgetHourMinuteString(Date dateTime)
get Hour Minute String
return new SimpleDateFormat("H:mm").format(dateTime);