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

StringformatToString(Date date)
format To String
String time = null;
SimpleDateFormat format = new SimpleDateFormat(FROMAT);
time = format.format(date);
return time;
StringformatUIDate(Calendar calendar)
Utility routine that takes in a Calendar referece and returns a date/time stamp suitable for use in a Portlets environment.
SimpleDateFormat fmt = null;
if ((calendar.get(Calendar.HOUR) == 0) && (calendar.get(Calendar.MINUTE) == 0)
        && (calendar.get(Calendar.SECOND) == 0)) {
    fmt = new SimpleDateFormat("dd-MMM-yy");
} else {
    fmt = new SimpleDateFormat("dd-MMM-yy hh:mm a");
return fmt.format(calendar.getTime());
...
StringformatUnixFileListing(final Date d)
Format the Date type.
final SimpleDateFormat df = new SimpleDateFormat("MMM dd HH:mm");
return df.format(d);
StringformatUnsignedVersion(String ver)
Convert long date stamp to '07-Jul 21:09 UTC' with month name in the system locale
if (ver != null) {
    try {
        long modtime = Long.parseLong(ver);
        return (new SimpleDateFormat("dd-MMM HH:mm")).format(new Date(modtime)) + " UTC";
    } catch (NumberFormatException nfe) {
return null;
...
StringformatValue(Object value)
format Value
if (value == null) {
    return "\"NULL\"";
if (value instanceof Date) {
    Date date = (Date) value;
    return "\"" + formatStoring.format(date) + "\"";
} else {
    return "\"" + value + "\"";
...
StringBufferformatVerbose(int level, String message, String source)
format Verbose
StringBuffer sb = new StringBuffer();
sb.append(DATE_FORMAT.format(new Date()));
sb.append(SEPARATOR).append(resolveLevel(level));
if (source != null && !source.equals("")) {
    sb.append(SEPARATOR).append(source);
if (message != null && !message.equals("")) {
    sb.append(SEPARATOR).append(message);
...
StringformatW3CDateTime(Date date)
create a W3C Date Time representation of a date.
SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormater.format(date);
StringformatW3CDateTime(Date date)
format WC Date Time
SimpleDateFormat df = new SimpleDateFormat(W3C_DATETIME_PATTERN);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(date);
StringformatWCPDate(String date, String sFormat)
This method returns the date formatted by the given format.
String sReturn = null;
Date dDate = new Date();
if ((date != null) && (date.length() != 0)) {
    SimpleDateFormat wcpFormat = new SimpleDateFormat("dd/MM/yyyy");
    try {
        dDate = wcpFormat.parse(date);
    } catch (Exception e) {
String sRealFormat = sFormat;
if ((sRealFormat == null) || sRealFormat.equals("")) {
    sRealFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
SimpleDateFormat sdf = new SimpleDateFormat(sRealFormat);
sReturn = fixedDateFormat(sdf, dDate);
return sReturn;
StringformatWithAge(Date date, String dateFormat, String suffix)
Provided a date you will get a timestamp and the age/old that you want.
if (date == null) {
    return null;
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
StringBuffer out = new StringBuffer();
out.append(format.format(date));
out.append(" - ");
Calendar now = Calendar.getInstance();
...