Java yyyy format(Date date)

Here you can find the source of format(Date date)

Description

format

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

String

Declaration

public static String format(Date date) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Iterator;
import java.util.Map;

public class Main {
    private static String DEFAULT_PATTERN = "yyyy-MM-dd";
    private static Map<String, SimpleDateFormat> formats;

    /**/*from   www  . ja  v  a  2s  .c  o  m*/
     * 
     * @param date
     *          
     * @param pattern
     *          
     * @return
     */
    public static String format(Date date, String pattern) {
        if (!formats.containsKey(pattern))
            pattern = DEFAULT_PATTERN;
        DateFormat format = formats.get(pattern);
        return format.format(date);
    }

    /**
     * @param date
     * @return  String
     */
    public static String format(Date date) {
        Iterator<SimpleDateFormat> iter = formats.values().iterator();
        while (iter.hasNext()) {
            return iter.next().format(date);
        }
        return null;
    }
}

Related

  1. format()
  2. format(Date aTs_Datetime)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)