Java Date to String convertDateToStr(Date date, String format)

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

Description

Date convert to String
------------------------------

License

Open Source License

Parameter

Parameter Description
date a parameter
format a parameter

Declaration

public static String convertDateToStr(Date date, String format) 

Method Source Code


//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

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

    /**/*w w  w. j  a va2 s  .  c  o m*/
     * Date convert to String <br>
     * ------------------------------<br>
     * 
     * @param date
     * @param format
     * @return
     */
    public static String convertDateToStr(Date date, String format) {
        SimpleDateFormat f = new SimpleDateFormat(format, Locale.SIMPLIFIED_CHINESE);
        return f.format(date);
    }

    /**
     * Date convert to String (yyyy-MM-dd HH:mm:ss) <br>
     * ------------------------------<br>
     * 
     * @param date
     * @return
     */
    public static String convertDateToStr(Date date) {
        return convertDateToStr(date, DEFAULT_DATE_PATTERN);
    }
}

Related

  1. convertDate2String8(Date time)
  2. convertDateTimeToString(Date date)
  3. convertDateTo(Date date, String patternToUse)
  4. convertDateToServerTimeZoneDate(DateFormat formatter, String timeZoneName, long milliSecond)
  5. convertDateToStr(Date d, String format)
  6. convertDateToString(final Date datum, final boolean withDay)
  7. convertDateToString(java.util.Date dt, String pattern)
  8. convertDateToString(String dateFormat, Date date)
  9. convertDateToString(String mask, Date date)