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

StringstdTimeFormat(Date date)
Formats a date by WGAs default time format HH:mm:SS
return DATEFORMAT_STANDARD.format(date);
longstring2Long(String sourceTime, String dataFormat)
string Long
long longTime = 0L;
DateFormat f = new SimpleDateFormat(dataFormat);
Date d = null;
try {
    d = f.parse(sourceTime);
} catch (ParseException e) {
    e.printStackTrace();
longTime = d.getTime();
return longTime;
longstring2long(String sourceTime, String dataFormat)
stringlong
long longTime = 0L;
DateFormat f = new SimpleDateFormat(dataFormat);
Date d = null;
try {
    d = f.parse(sourceTime);
} catch (ParseException e) {
    e.printStackTrace();
if (null == d)
    longTime = 0;
else
    longTime = d.getTime();
return longTime;
StringstringDateTimeFormat(String dt2Format)
string Date Time Format
return new SimpleDateFormat(DATETIME_WITHOUT_SS_FORMAT).format(parseDateTime(dt2Format));
longstringTimeToLongTime(String time, String format)
string Time To Long Time
if (format.isEmpty())
    format = "yyyyMMdd-HHmmss-SSS";
try {
    return new SimpleDateFormat(format).parse(time).getTime();
} catch (ParseException e) {
    throw new IOException(e);
DatestringToTime(String format, String sDate)
string To Time
DateFormat df = new SimpleDateFormat(format);
Date _date = df.parse(sDate);
if (timeToString(format, _date).equals(sDate)) {
    return _date;
} else {
    throw new Exception(sDate + " is error");
Stringtime2Date(Integer time, String format)
time Date
String date = "";
SimpleDateFormat sdf = new SimpleDateFormat(format);
date = sdf.format(new Date(time * 1000l));
return date;
Stringtime2String(Date time, DateFormat dateFormat)
time String
if (time == null)
    return null;
return dateFormat.format(time);
StringtimeFormatDate(Date d)
time Format Date
return timeFormat.format(d);
StringtimeFormatNano(long delta)
time Format Nano
StringBuilder sb = new StringBuilder();
if (delta > ONE_BILLION * 60) {
    sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / (ONE_BILLION * 60)) + ":");
} else {
    sb.append("00:");
if (delta > ONE_BILLION) {
    sb.append(FORMAT_DOUBLE_NO_FRACTION.format(delta / ONE_BILLION) + "::");
...