Java Utililty Methods Hour Format

List of utility methods to do Hour Format

Description

The list of methods to do Hour Format are organized into topic(s).

Method

StringformatDate(Date date, String format)
format Date
if (date == null)
    return null;
String str_date = null;
if (format != null) {
    DateFormat formater = new SimpleDateFormat(format);
    str_date = formater.format(date);
} else {
    str_date = datefmt.format(date);
...
StringformatDate(Date date, String format)
format Date
return date != null && format != null ? new SimpleDateFormat(format).format(date) : null;
StringformatDate(Date date, String format, Locale locale)
format Date
SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
return sdf.format(date);
StringformatDate(Date date, String patter)
format Date
try {
    SimpleDateFormat sdf = new SimpleDateFormat(patter);
    return sdf.format(date);
} catch (RuntimeException e) {
    return "";
StringformatDate(Date date, String pattern)
format Date
if (date == null)
    return "";
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return formatCalendar(calendar, pattern);
StringformatDate(Date date, String pattern)
Formats the given date according to the specified pattern.
SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
formatter.setTimeZone(GMT);
return formatter.format(date);
StringformatDate(Date date, String timeFormat, String timeZone)
format Date
SimpleDateFormat sdf = getDateFormatter(timeFormat);
TimeZone ltz = TimeZone.getDefault();
Date nd = date;
TimeZone tz = TimeZone.getTimeZone(timeZone);
if (ltz.hasSameRules(tz) == false) {
    long lo = ltz.getRawOffset();
    long to = tz.getRawOffset();
    nd = new Date(date.getTime() - lo + to);
...
voidformatDate(Date date, StringBuffer buffer)
format Date
ISO8601_FORMAT_OUT.format(date, buffer, new FieldPosition(0));
StringformatDate(Date date, TimeZone tz)
Method description
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
if (tz != null) {
    sdf.setTimeZone(tz);
return sdf.format(date);
StringformatDate(Date dateString)
This function converts the current date string to appropirate database string representation
try {
    SimpleDateFormat sdf = new SimpleDateFormat();
    sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
    return sdf.format(dateString);
} catch (Exception e) {
    e.printStackTrace();
return "";
...