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

SimpleDateFormatgetXsdDateTimeFormat()
Returns a SimpleDateFormat allowing to read and write ^^xsd:date
return (SimpleDateFormat) XSD_DATE_TIME_FORMAT.clone();
DateTimeFormattergetXSDFormatter(DateTime date)
get XSD Formatter
int len = 0;
int millis = date.getMillisOfSecond();
if (millis > 0) {
    DecimalFormat df = new DecimalFormat(".###");
    double d = millis / 1000.0;
    len = String.valueOf(df.format(d)).length() - 1;
return getXSDFormatter(len);
...
booleanisDateFormat(String timeString)
is Date Format
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setLenient(false);
try {
    format.parse(timeString);
} catch (Exception e) {
    return false;
return true;
...
Stringlong2Datestr(long time, String format)
long Datestr
if (format == null || format.trim().equals(""))
    format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(time);
Stringlong2String(long longTime, String dataFormat)
long String
Date d = new Date(longTime);
SimpleDateFormat s = new SimpleDateFormat(dataFormat);
String str = s.format(d);
return str;
Stringlong2String(long longTime, String dataFormat)
long String
String str = "";
try {
    Date d = new Date(longTime);
    SimpleDateFormat s = new SimpleDateFormat(dataFormat);
    str = s.format(d);
} catch (Exception e) {
    str = "";
return str;
DateFormatnewDateTimeFormat()
new Date Time Format
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
f.setTimeZone(TimeZone.getTimeZone("UTC"));
return f;
StringprintDate(final long time, final String dateFormat)
print Date
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(getDate(time, false) * 1000);
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(cal.getTime());
StringprintFormatDate(long dateTime)
print Format Date
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.").format(dateTime / 1000)
        + String.format("%06d", dateTime % 1000000);
voidsetDateTimeFormat(String format)
Give the possibility to change to datetime format as it differs across several database systems
dateTimeFormat.applyPattern(format);