Java yyyy formatDate(Date date, String pattern)

Here you can find the source of formatDate(Date date, String pattern)

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date date, String pattern) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static String formatDate(Date date, String pattern) {
        if (pattern == null || pattern.equals("") || pattern.equals("null")) {
            pattern = "yyyy-MM-dd";
        }//from   w  w w. ja v  a  2s. c o m
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    /**
     * Returns a string the represents the passed-in date parsed according to
     * the passed-in format. Returns an empty string if the date or the format
     * is null.
     **/
    public static String format(Date aDate, SimpleDateFormat aFormat) {
        if (aDate == null || aFormat == null) {
            return "";
        }
        synchronized (aFormat) {
            return aFormat.format(aDate);
        }
    }
}

Related

  1. formatDate(Date date, String datePattern)
  2. formatDate(Date date, String format)
  3. formatDate(Date date, String format)
  4. formatDate(Date date, String outputPattern)
  5. formatDate(Date date, String pattern)
  6. formatDate(Date date, String pattern)
  7. formatDate(Date date, String pattern)
  8. FormatDate(Date date, String sf)
  9. formatDate(Date date, TimeZone timeZone)