Java Date Format formatDate(final Date date)

Here you can find the source of formatDate(final Date date)

Description

format Date

License

Apache License

Declaration

public static String formatDate(final Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_PATTERN = "yyyy-MM-dd";

    /**//from   w  ww .j  av a 2  s  .  co  m
     * format date by given pattern
     */
    public static String formatDate(final Date date, String pattern) {
        if (date == null) {
            return null;
        }
        if (pattern == null) {
            pattern = DEFAULT_PATTERN;
        }
        final SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }

    public static String formatDate(final Date date) {
        if (null == date) {
            return "";
        }
        final SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN);
        return formatter.format(date);
    }
}

Related

  1. formatDate(final Calendar date)
  2. formatDate(final Date dat)
  3. formatDate(final Date date)
  4. formatDate(final Date date)
  5. formatDate(final Date date)
  6. formatDate(final Date date)
  7. formatDate(final Date date)
  8. formatDate(final Date date)
  9. formatDate(final java.util.Date date)