Java Utililty Methods Hour Calculate

List of utility methods to do Hour Calculate

Description

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

Method

doublegetDoubleValue(String hours)
get Double Value
double doubleValue = 0.0;
try {
    doubleValue = getStandardHoursNumberFormat().parse(hours).doubleValue();
} catch (ParseException e) {
    doubleValue = Double.valueOf(hours);
return doubleValue;
StringgetExpiresDate(int hours)
get Expires Date
GregorianCalendar calendar = new GregorianCalendar();
calendar.add(Calendar.HOUR, hours);
Date date = calendar.getTime();
return dateToRFC1123(date);
longgetTime(String dateStr, int hour, String timeZone)
get Time
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    Date date = simpleDateFormat.parse(dateStr + " " + hour + ":00:00");
    return date.getTime();
} catch (ParseException ex) {
    System.out.println("Exception " + ex);
return 0L;
longgetTimestampFromDateHour2(String d)
get Timestamp From Date Hour
try {
    return HOUR_NAME_FORMAT2.parse(d).getTime();
} catch (ParseException e) {
    e.printStackTrace();
return 0;
StringgetTimeStringOfHourBefore(int hour)
get Time String Of Hour Before
final Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.HOUR, hour * -1);
return getTimestampFormat().format(calendar.getTime());
DategetTomorrowSixHours()
get Tomorrow Six Hours
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_YEAR, 1);
c.add(Calendar.HOUR_OF_DAY, 6);
Date date = c.getTime();
String t = dayFormater.format(date);
try {
    date = dayFormater.parse(t);
} catch (ParseException e) {
...
DategetWeeHours()
get Wee Hours
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
StringhoursMinsSecsFromMs(long ms)
hours Mins Secs From Ms
NumberFormat nf = NumberFormat.getIntegerInstance();
nf.setMinimumIntegerDigits(2);
long hours = ms / MS_IN_HOUR;
long hourRem = ms - (hours * MS_IN_HOUR);
long mins = hourRem / MS_IN_MIN;
long minsRem = hourRem - (mins * MS_IN_MIN);
long secs = minsRem / MS_IN_SEC;
return hours + ":" + nf.format(mins) + ":" + nf.format(secs);
...
booleanisHourMinute(String str)
is Hour Minute
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
dateFormat.setLenient(false);
try {
    dateFormat.parse(str);
    return true;
} catch (Exception e) {
    return false;
booleanisValidTime(int hour, int minute, boolean ampm)
is Valid Time
if (minute < 0 || minute > 59)
    return false;
if (ampm && (hour < 1 || hour > 12))
    return false;
else if (hour < 0 || hour > 23)
    return false;
else
    return true;
...