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

StringformatDateInTime(Date date)
format Date In Time
return LOG_DATE_IN_HOUR_FORMAT.format(date);
StringformatDateRfc822(Date date, String timeZoneId)
Format a Date in RFC822 with the given time zone.
if (date != null) {
    TimeZone tZone = TimeZone.getTimeZone(timeZoneId);
    SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
    dateFormater.setTimeZone(tZone);
    return dateFormater.format(date);
return null;
StringformatDateString(Date d)
format Date String
String dateFormat = "yyyyMMddHHmm";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(dateFormat);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(d);
StringformatDateString(String dateString)
format Date String
try {
    if ("".equals(dateString) || dateString == null) {
        return null;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse(dateString);
    sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
    return sdf.format(date);
...
StringformatDateString2(String str_date)
format Date String
String[] patterns = new String[6];
Pattern p0;
Pattern p1;
Pattern p2;
Pattern p3;
Pattern p4;
Pattern p5;
patterns[0] = "(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/((\\d\\d)|((19|20)\\d\\d))\\s([1-9]|([01][0-9])|(2[1-3])):((0[0-9])|([12345][0-9])):((0[0-9])|([12345][0-9])).[0-9]*";
...
StringformatDateTime()
format Date Time
return formatDateTime(new Date(System.currentTimeMillis()));
StringformatDateTime(Calendar cal)
format Date Time
synchronized (dtg) {
    if (cal == null) {
        return "unknown";
    return dtg.format(cal.getTime());
StringformatDateTime(Calendar dateTime)
format Date Time
assert dateTime != null : "Parameter 'dateTime' of method 'formatDateTime' must not be null";
return DATE_TIME_FORMAT.format(new Date(dateTime.getTimeInMillis()));
StringformatDateTime(Calendar time)
format Date Time
if (time == null) {
    return "";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return df.format(time.getTime());
StringformatDateTime(Date d)
Convert date and time to string like "yyyy-MM-dd HH:mm".
return new SimpleDateFormat(DATETIME_FORMAT).format(d);