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

StringgetStringFromTime(Date time, String format)
get String From Time
if (format == null || format.trim().equals("")) {
    sdf.applyPattern(FORMAT_DATE_TIME);
} else {
    sdf.applyPattern(format);
return sdf.format(time);
StringgetSysDateTimeForFileName()
get Sys Date Time For File Name
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy_HH_mm");
try {
    return dateFormat.format(calendar.getTime());
} catch (Exception e) {
    throw e;
StringgetSysTimeYMDHMS2()
get Sys Time YMDHMS
return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
longgetTime(@Nonnull String format, @Nonnull String date, @Nonnull String tz)
get Time
checkNotNull(format);
checkNotNull(date);
checkNotNull(tz);
try {
    DateFormat dateFormat = new SimpleDateFormat(format);
    dateFormat.setTimeZone(TimeZone.getTimeZone(tz));
    return dateFormat.parse(date).getTime();
} catch (ParseException e) {
...
StringgetTime(Date dt, String format)
get Time
SimpleDateFormat st = new SimpleDateFormat(format);
return st.format(dt);
StringgetTime(Date time, int format, Locale locale)
get Time
return SimpleDateFormat.getTimeInstance(format, locale).format(time);
StringgetTime(DateFormat df)
get Time
return df.format(new Date());
StringgetTime(int format)
get Time
if (format == 0) {
    return FORMAT4NAME.format(new Date());
} else {
    return FORMAT4LOG.format(new Date());
StringgetTime(long time, int timeFormat)
get Time
return timeFormat == HOURS_24_MAKE ? getTimeOf24(time) : getTimeOf12(time);
longgetTime(String dateStr, String format)
get Time
long time = -1;
Date date = getDate(dateStr, format);
if (date != null) {
    time = getDate(dateStr, format).getTime();
return time;