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

StringformatDateTime(java.util.Date d)
format Date Time
SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
return (df.format(d) + " " + sdf.format(d));
StringformatDateTime(java.util.Date date)
format Date Time
return formatDateTime(DEFAULT_DATE_FROMAT, date);
StringformatDateTime(java.util.Date date)
format Date Time
return format(date, "yyyy-MM-dd HH:mm:ss");
StringformatDateTime(java.util.Date paramDate)
format Date Time
if (paramDate == null)
    return null;
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
localSimpleDateFormat.setLenient(false);
return localSimpleDateFormat.format(paramDate);
DateformatDateTime(String date)
format Date Time
date = date.replaceAll("Atualizadas em", "").replace(" ", "");
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyyHH:mm");
try {
    return format.parse(date);
} catch (ParseException e) {
    e.printStackTrace();
    return null;
StringFormatDateTime(String dateString)
Formats the regular date string into a more humanly readable one
Date date;
String formattedDate = dateString;
String pattern = (dateString.indexOf('T') == -1) ? "yyyy-MM-dd HH:mm:ss.S" : "yyyy-MM-dd'T'HH:mm:ss";
try {
    date = new SimpleDateFormat(pattern).parse(dateString);
    formattedDate = new SimpleDateFormat("MMMM dd, yyyy, h:mm:ss a").format(date);
} catch (ParseException e) {
    e.printStackTrace();
...
StringformatDateTime(String dateTime)
format Date Time
try {
    dateTime = dateTime.substring(0, 22) + dateTime.substring(23, 25);
    String pattern = "yyyy-MM-dd HH:mm:ssZ";
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    Date date = sdf.parse(dateTime);
    String newPattern = "dd MMM yyyy h:mm aaa zzz";
    SimpleDateFormat myFormat = new SimpleDateFormat(newPattern);
    return myFormat.format(date);
...
StringformatDateTime(String strDateTime, String strFormat)
format Date Time
String sDateTime = strDateTime;
try {
    Calendar Cal = parseDateTime(strDateTime);
    SimpleDateFormat sdf = null;
    sdf = new SimpleDateFormat(strFormat);
    sDateTime = sdf.format(Cal.getTime());
} catch (Exception e) {
return sDateTime;
voidformatDateTime12(String dateStr)
format Date Time
SimpleDateFormat parseFormat = new SimpleDateFormat("dd/mm/yy HH:mm:ss zz");
SimpleDateFormat displayFormat = new SimpleDateFormat("dd/mm/yy hh:mm:ss a zz");
String[] tz = dateStr.split(" ");
TimeZone firstTime = TimeZone.getTimeZone(tz[tz.length - 1]);
parseFormat.setTimeZone(firstTime);
displayFormat.setTimeZone(firstTime);
Date date = null;
try {
...
voidformatDateTime24()
format Date Time
SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a");
Date date = null;
try {
    date = parseFormat.parse("10:30 PM");
} catch (ParseException e) {
    e.printStackTrace();
System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date));