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

StringgetCurDateTime(String formatStr)
get Cur Date Time
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
String now = sdf.format(new Date());
return now;
StringgetCurDateTimeFormat(String Format)
get Cur Date Time Format
Calendar now = Calendar.getInstance(TimeZone.getDefault());
DateFormat sdf = new SimpleDateFormat(Format);
sdf.setTimeZone(TimeZone.getDefault());
return (sdf.format(now.getTime()));
StringgetCurrDatetimeWithDbFormat()
get Curr Datetime With Db Format
DateFormat dbDateFormat = dbDateFormatThreadLocal.get();
return dbDateFormat.format(new Date());
StringgetCurTime(String dateformat)
get Cur Time
Calendar calendar = new GregorianCalendar();
Date date = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat(dateformat);
return format.format(date);
SimpleDateFormatgetDefaultDatetimeFormat()
get Default Datetime Format
return new SimpleDateFormat(DEFAULT_DATETIME_FORMAT_PATTERN);
DateFormatgetDefaultPropertyPageDateTimeFormat()
The default DateFormat to be used in property pages (used by implementations of IPropertySource ).
return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
StringgetEndDate(String time, SimpleDateFormat dateFormat)
get End Date
Date nowDate = new Date();
Date timeDate = stringToDate(time, dateFormat);
String endDate = "";
if (timeDate.after(nowDate)) {
    endDate = dateFormat.format(nowDate);
} else {
    endDate = dateFormat.format(timeDate);
return endDate;
StringgetFormat2TimetagStr()
get Format Timetag Str
return format2.format(new Date());
StringgetFormatDate(Date date, boolean ShowTimePart_in)
get Format Date
if (ShowTimePart_in) {
    return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
} else {
    return (new SimpleDateFormat("yyyy-MM-dd")).format(date);
StringgetFormatDate(String timeString, String format)
get Format Date
long timeLong = 0L;
if (timeString == null || timeString.length() == 0) {
    timeLong = (new Date()).getTime();
} else {
    timeLong = Long.valueOf(timeString).longValue();
Date date = new Date();
date.setTime(timeLong);
...