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 src, String formatPattern)
format Date
if (src == null) {
    return "";
DateFormat fmt = new SimpleDateFormat(formatPattern);
return fmt.format(src);
StringformatDate(final Date date, final String pattern)
Formats the given date according to the specified pattern.
if (date == null)
    throw new IllegalArgumentException("date is null");
if (pattern == null)
    throw new IllegalArgumentException("pattern is null");
final SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
formatter.setTimeZone(GMT);
return formatter.format(date);
StringformatDate(final Date date, String pattern)
format date by given pattern
if (date == null) {
    return null;
if (pattern == null) {
    pattern = DEFAULT_PATTERN;
final SimpleDateFormat formatter = new SimpleDateFormat(pattern);
return formatter.format(date);
...
StringformatDate(final String date)
format Date
if (date.isEmpty())
    return date;
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date formattedDate = df.parse(date);
return formatedDateWithTime(formattedDate);
StringformatDate(java.util.Date date, String pattern)
format Date
SimpleDateFormat formatterOut = new SimpleDateFormat(pattern);
return formatterOut.format(date);
StringformatDate(java.util.Date dtFormat, String sFormatString)
Format dates, convenience method
return formatDate(dtFormat, sFormatString, Locale.getDefault(), TimeZone.getDefault());
StringformatDate(Object obj, String format)
format Date
if (obj == null || obj.toString() == "") {
    return "";
SimpleDateFormat dateFormat = null;
if (DAY_STR.equals(format)) {
    dateFormat = DAY_FORMAT;
} else if (TIME_STR.equals(format)) {
    dateFormat = TIME_FORMAT;
...
DateformatDate(String date)
format Date
return format(date, "yyyy-MM-dd");
StringformatDate(String date)
format Date
String str = "";
if (date == null || date.equals("")) {
    str = "";
} else if (date.length() >= 10) {
    str = date.substring(0, 10);
} else {
    str = date;
return str;
StringformatDate(String dateTimeString)
Extracts date and month from dateTimeString and formats
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
try {
    date = dateFormat.parse(dateTimeString);
} catch (ParseException e) {
    e.printStackTrace();
Calendar cal = Calendar.getInstance();
...