Here you can find the source of date2Str(Date date, String format)
Parameter | Description |
---|---|
date | a parameter |
format | a parameter |
public static String date2Str(Date date, String format)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**// w w w . j a v a 2 s . c o m * convert a date to a format string default format:yyyy-MM-dd HH:mm:ss * * @param date * @param format * @return */ public static String date2Str(Date date, String format) { if (date != null) return long2Datestr(date.getTime(), format); else return long2Datestr(new Date().getTime(), format); } public static String long2Datestr(long time, String format) { if (format == null || format.trim().equals("")) format = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(time); } }