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

StringformatOptimal(Date d)
Formats a Date to a String, leaving out trailing zero values.
String result;
if ((d.getTime() % 1000) == 0) {
    if (d.getSeconds() == 0) {
        if (d.getMinutes() == 0 && d.getHours() == 0) {
            result = format(d, "yyyy-MM-dd");
        } else {
            result = format(d, "yyyy-MM-dd HH:mm");
    } else {
        result = format(d, "yyyy-MM-dd HH:mm:ss");
} else {
    result = format(d, "yyyy-MM-dd HH:mm:ss.SSS");
return result;
StringformatPrice(double price, String style)
format Price
NumberFormat nf = new DecimalFormat(style);
return nf.format(price);
StringformatRawDateTime(int unixtime)
format Raw Date Time
return DATE_TIME_FORMAT.format(new Date(unixtime * 1000L));
StringformatRecyclingDate(String strDate)
format Recycling Date
try {
    SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    if (strDate.trim().isEmpty())
        return blankField;
    else {
        Date dt = input.parse(strDate);
        SimpleDateFormat output = new SimpleDateFormat("MM/dd/yy HH:mm");
        if (dt != null)
...
StringformatRFC1123(Date date)
Formats the given Date to a string in RFC1123 format.
SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_RFC1123_DATE, Locale.US);
sdf.setTimeZone(TIMEZONE_GMT);
return sdf.format(date);
StringformatRfc3339Date(Date date)
format Rfc Date
return formatRfc3339Date(date, null);
StringformatRFC822(Date date)
format RFC
return rfc822DateFormat.format(date);
StringformatRFC822(Date date, Locale locale)
format RFC
SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", locale);
dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormater.format(date);
StringformatRFC822(Date date, String timezone)
Format given date as an RFC822 formatted date/time String.
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
if (timezone != null) {
    dateFormat.setTimeZone(TimeZone.getTimeZone(timezone));
String dateString = null;
if (date != null) {
    dateString = dateFormat.format(date);
return dateString;
StringformatRfc822Date(Date date)
format Rfc Date
synchronized (rfc822DateParser) {
    return rfc822DateParser.format(date);