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(String format)
format Date
return formatDate(format, new Date());
StringformatDate(String inputStr)
format Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
    return sdf.format(sdf.parse(inputStr));
} catch (ParseException e) {
    e.printStackTrace();
return "";
StringformatDate(String pattern, Date date)
Formats a java.util.Date object into a string according to a specified pattern.
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
StringformatDate2DateTimeStr()
Format the current date time to "yyyy-MM-dd HH:mm:ss" format string.
return formatDate2DateTimeStr(new Date());
StringformatDate2DateTimeStr()
Format the current date time to "yyyy-MM-dd HH:mm:ss" format string.
return formatDate2DateTimeStr(new Date());
StringformatDate3DateTimeStr(Date date)
format Date Date Time Str
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return s.format(date);
StringformatDateAddHMS(String strDate)
format Date Add HMS
String strNewDate = "";
if (strDate != null && strDate.length() > 8) {
    if (strDate.length() <= 14) {
        strNewDate = strDate;
    } else {
        strNewDate = strDate.substring(0, 14);
} else {
...
StringformatDateAndTime(Date date)
Format date and time.
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sd.format(date);
StringformatDateAsString(Date date)
format Date As String
SimpleDateFormat formatter = new SimpleDateFormat("MMM d, Y @ hh:mma");
DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
symbols.setAmPmStrings(new String[] { "am", "pm" });
formatter.setDateFormatSymbols(symbols);
return formatter.format(date);
StringformatDateForCERMe(Date date, boolean includeTime)
Method formatDateForCERMe.
if (date != null) {
    if (includeTime)
        return new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a").format(date);
    else
        return new SimpleDateFormat("MM-dd-yyyy").format(date);
} else
    return null;