Java Utililty Methods Time Format

List of utility methods to do Time Format

Description

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

Method

longgetTimeFromString(String time, SimpleDateFormat formatter)
get Time From String
if (time.toLowerCase().equals("latest")) {
    return Long.MAX_VALUE;
if (time.toLowerCase().equals("bot")) {
    return Long.MIN_VALUE;
return formatter.parse(time).getTime();
DategetTimeFromString(String timeStr, String format)
get Time From String
if (format == null || format.trim().equals("")) {
    sdf.applyPattern(FORMAT_DATE_TIME);
} else {
    sdf.applyPattern(format);
try {
    return sdf.parse(timeStr);
} catch (ParseException e) {
...
StringgetTimeInProvenanceFormat(Date date)
get Time In Provenance Format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
sdf.setTimeZone(TimeZone.getDefault());
return sdf.format(date);
DateFormatgetTimeOnlyDateFormat()
get Time Only Date Format
return new SimpleDateFormat("HH:mm:ss z");
StringgetTimeOnlyWithNumber()
get Time Only With Number
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
return formatter.format(new Date());
StringgetTimeQuantum(String strDate, String format)
get Time Quantum
Date mDate = getDateByFormat(strDate, format);
int hour = mDate.getHours();
if (hour >= 12)
    return "PM";
else
    return "AM";
StringgetTimeStringFormatedForSWANWithDelim(final Object pObjTime, final String pStrDelim)
get Time String Formated For SWAN With Delim
String lStrTimeRes = ""; 
SimpleDateFormat lDateFormatter;
lDateFormatter = new SimpleDateFormat("yyyyMMdd" + pStrDelim + "HHmmss"); 
if (pObjTime instanceof String) {
    lStrTimeRes = (String) pObjTime;
    SimpleDateFormat lDateFormatterLoc = new SimpleDateFormat();
    try {
        Date lDate = lDateFormatterLoc.parse(lStrTimeRes);
...
StringgetTimeSystem(String formatTime)
get Time System
String timeSystem = null;
try {
    if (formatTime == null) {
        formatTime = "HH:mm:ss";
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(formatTime);
    java.util.Date date = new java.util.Date();
    timeSystem = format.format(date);
...
longgetTwoTimeInterval(String startTime, String endTime, String format)
get Two Time Interval
SimpleDateFormat df = new SimpleDateFormat(format);
try {
    Date starDate = df.parse(startTime);
    Date endDate = df.parse(endTime);
    return endDate.getTime() - starDate.getTime();
} catch (ParseException e) {
    e.printStackTrace();
return 0;
SimpleDateFormatgetUniversalDateTimeFormat()
Returns a formatter for the universal date/time format
return new SimpleDateFormat(UNIVERSAL_TIMEFORMAT);