Java Utililty Methods Date Format As

List of utility methods to do Date Format As

Description

The list of methods to do Date Format As are organized into topic(s).

Method

StringformatDateToDefault(Date date)
Format a date for display to a user, in the default time zone.
DateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.getDefault());
format.setTimeZone(TimeZone.getDefault());
String rv = format.format(date);
return rv;
StringformatDateToMD(Date date)
format Date To MD
SimpleDateFormat fmt = new SimpleDateFormat("dd/MM", Locale.CHINA);
return fmt.format(date);
StringformatDateToMinutes(Date date)
Method formatDateToMinutes.
if (date != null)
    return new SimpleDateFormat("MM/dd/yyyy hh:mm a").format(date);
else
    return null;
StringformatDateToUTC(Date date)
format Date To UTC
DateTime dateTime = new DateTime(date);
return utcFormatter.print(dateTime);
StringformatDateToUTC(final Date date)
format Date To UTC
DateFormat simpleDateFormat = new SimpleDateFormat(DATE_UTC_FORMAT, Locale.US);
return simpleDateFormat.format(date) + "Z";
StringformatDateUsingW3C(Date date)
Use to produce date Strings in the W3C date format
String w3cDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date);
return w3cDate = w3cDate.substring(0, 22) + ":" + w3cDate.substring(22, 24);
StringformatDateUTC(Date d)
format Date UTC
return (d != null) ? getISO8601DateFormat().format(d) : "NULL";
StringformatDateUTC(Date date)
format Date UTC
return (date != null) ? getDateFormat().format(date) : null;
StringformatDateW3C(Date date)
format Date WC
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String text = df.format(date);
return text.substring(0, 22) + ":" + text.substring(22);
StringformatDateWithMilliseconds(DateFormat aFormat, Date aDate)
Performs date formatting using the provided format, but injects millisecond precision if the millisecond value is not "000".
DateFormat tempFormat = aFormat;
if (aDate.getTime() % 1000 != 0) {
    if (aFormat instanceof SimpleDateFormat) {
        Field tempField;
        try {
            tempField = SimpleDateFormat.class.getDeclaredField("pattern");
            tempField.setAccessible(true);
            String tempPattern = (String) tempField.get(aFormat);
...