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

StringgetFormattedFileTime(File f, String format)
get Formatted File Time
try {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(f.lastModified());
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(cal.getTime());
} catch (SecurityException ignored) {
    return "";
StringgetFormattedTime()
get Formatted Time
DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
return format.format(new Date());
StringgetFormattedTime(Date date)
get Formatted Time
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
formatter.getCalendar().setTimeZone(TimeZone.getTimeZone("UTC"));
return formatter.format(date);
StringgetFormattedTime(Date date)
get Formatted Time
assert date != null;
SimpleDateFormat formatter = new SimpleDateFormat(DISPLAYED_FORMATTED_TIME);
String formattedTime = formatter.format(date);
return formattedTime;
StringgetFormattedTime(final Calendar calendar)
Function to return formatted time
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(calendar.getTime());
StringgetFormattedTime(final Date date)
get Formatted Time
if (date == null) {
    return null;
return createSimpleFormat().format(date);
StringgetFormattedTimeFilesafe(long t)
get Formatted Time Filesafe
return dateFormattingFilesafe.format(new Date(t));
StringgetFormattedTimeString(double s)
get Formatted Time String
int hours = (int) s; 
int minutes = (int) ((s - hours) * 60); 
double seconds = (s - hours) * 3600 - minutes * 60; 
if (s < 0) {
    minutes = -minutes;
    String ss = null;
    if (seconds < 10) {
        ss = "0" + fmt.format(-seconds);
...
StringgetFormatTime(Date date)
get Format Time
return getFormatDateTime(date, "yyyy-MM-dd HH:mm:ss");
StringgetFormatTime(String format)
get Format Time
sFormat = new SimpleDateFormat(format, Locale.CHINA);
return sFormat.format(new Date());