Java Date to String DateToString(Date date)

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

Description

Convert date to string , default pattern is yyyy-MM-dd

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String DateToString(Date date) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    /**/*w  ww . j av  a2  s . c  o m*/
     * Convert date to string , default pattern is yyyy-MM-dd
     * @param date
     * @return
     * @Create Sin@2012/2/22
     */
    public static String DateToString(Date date) {
        return DateToString(date, DATE_PATTERN);
    }

    /**
     * Convert date to string
     * @param date
     * @param pattern
     * @return
     * @Create Sin@2012/2/22
     */
    public static String DateToString(Date date, String pattern) {
        if (date == null) {
            return "";
        } else {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            return df.format(date);
        }

    }
}

Related

  1. dateToString(Date date)
  2. dateToString(Date date)
  3. dateToString(Date date)
  4. dateToString(Date date)
  5. dateToString(Date date)
  6. dateToString(Date date)
  7. dateToString(Date date)
  8. dateToString(Date date)
  9. dateToString(Date date, String dateFormat)