Java Utililty Methods Date Format

List of utility methods to do Date Format

Description

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

Method

Datedateformat(String dateTime)
dateformat
SimpleDateFormat formatter = null;
int dot = dateTime.indexOf('.');
int col = dateTime.indexOf(':');
if (col > 0) {
    if (dot > 0) {
        formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    } else {
        formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
...
StringdateFormat(String datetime)
date Format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date date = null;
try {
    date = sdf.parse(datetime);
} catch (ParseException e) {
    e.printStackTrace();
Calendar cl = Calendar.getInstance();
...
SimpleDateFormatdateFormat(String df, TimeZone timeZone)
date Format
SimpleDateFormat ret = new SimpleDateFormat(df);
ret.setTimeZone(timeZone);
return ret;
StringdateFormat(String format, java.util.Date date)
date Format
return dateFormat(format, date, null, null);
StringdateFormat(String format, java.util.Date date, String tz, Locale locale)
date Format
if (date == null) {
    return null;
if (format == null) {
    for (int i = 0; i < tsDefaultFormats.length; i++) {
        String dFormat = tsDefaultFormats[i];
        try {
            String df = dateFormat(dFormat, date, tz, locale);
...
StringdateFormat(String format, String defaultFormat)
date Format
if (format != null && !format.trim().isEmpty()) {
    format = format.trim();
    if (format.startsWith("fmt:")) {
        format = format.substring(4);
        format = format.replace("%Y", "yyyy");
        format = format.replace("%y", "yy");
        format = format.replace("%m", "MM");
        format = format.replace("%d", "dd");
...
Datedateformat(String text, String format)
dateformat
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = simpleDateFormat.parse(text);
return date;
StringdateFormat3(Date date)
date Format
if (date == null) {
    return null;
} else {
    return sdf3.format(date);
SimpleDateFormatdateFormat4yyyyMMdd()
date Formatyyyy M Mdd
return new SimpleDateFormat("yyyy-MM-dd");
DatedateFormatCheck(String source)
date Format Check
return dateFormatCheck(source, "yyyyMMdd");