Java yyyy format(Date date, String format)

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

Description

format

License

Apache License

Declaration

public static String format(Date date, String format) 

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 DATE_FORMAT = "yyyy-MM-dd";

    /**//w  w  w .j a  v  a 2 s. c  o  m
     * @throws CloudException 
     * 
    * @Title: format
    * @param: date
    * @param: format
    * @return: Date
    * @throws
     */
    public static Date format(String date, String format) {
        try {
            return new SimpleDateFormat(format).parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @throws CloudException 
    * @Title: format
    * @param: date
    * @return: Date
    * @throws
     */
    public static Date format(String date) {
        return format(date, DATE_FORMAT);
    }

    /**
     * 
    * @Title: format
    * @param: date
    * @param: format
    * @return: String
    * @throws
     */
    public static String format(Date date, String format) {
        return new SimpleDateFormat(format).format(date);
    }

    /**
     * 
    * @Title: format
    * @param: date
    * @return: String
    * @throws
     */
    public static String format(Date date) {
        return format(date, DATE_FORMAT);
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date, String pattern)
  7. format(Date date, String pattern)
  8. format(Date pDt)
  9. format(final Date date, final String pattern)