Java Utililty Methods Hour Format

List of utility methods to do Hour Format

Description

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

Method

StringformatTime(long time)
Takes an elapsed time (in milliseconds) and turns it into a stopwatch style time
DateFormat dateFmt = new SimpleDateFormat("HH:mm:ss");
dateFmt.setTimeZone(TimeZone.getTimeZone("GMT-0"));
return dateFmt.format(new Date(time));
StringformatTime(long time)
Format time for human readers
DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS");
String str = df.format(time);
return str;
StringformatTime(long time, TimeUnit unit)
format Time
String format = "HH:mm:ss";
if (unit.toHours(time) < 1) {
    format = "mm:ss";
return formatTime(time, unit, format);
StringformatTime(String dateTimeString)
Extracts hour and minutes from a dateDimestring
String formattedTime = "";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
try {
    date = dateFormat.parse(dateTimeString);
} catch (ParseException e) {
    e.printStackTrace();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
String hour;
if (cal.get(Calendar.HOUR_OF_DAY) < 10) {
    hour = "0" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
} else {
    hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
String minute;
if (cal.get(Calendar.MINUTE) < 10) {
    minute = "0" + String.valueOf(cal.get(Calendar.MINUTE));
} else {
    minute = String.valueOf(cal.get(Calendar.MINUTE));
formattedTime = formattedTime + " " + hour + ":" + minute;
return hour + ":" + minute;
DateformatTime_(String time)
format Tim_
time = time.replaceAll("T", " ");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+0000");
return format.parse(time);
StringformatTime_1(long time_value)
format Tim_
time_format_1.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
return time_format_1.format(new Date(time_value));
StringformatTime_2(long time_value, long frame_rate)
format Tim_
time_format_2.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
String time_str = time_format_2.format(new Date(time_value));
return (time_str.substring(0, time_str.length() - 3) + adaptString(
        (Integer.parseInt(time_str.substring(time_str.length() - 3)) * 90 / (int) frame_rate), 2));
StringformatToHour(Date date)
format To Hour
java.text.DateFormat format = new java.text.SimpleDateFormat("yyyyMMddHH");
return format.format(date);
StringformatToOpenMrsDate(Date date)
Parses the given Date to the String representation of that date in the format used by the OpenMRS.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
return dateFormat.format(date.getTime());
StringformatToSec(Date date)
format To Sec
return format(date, "yyyyMMdd_HHmmss");