Here you can find the source of dateToStringWithTime(Date date)
public static String dateToStringWithTime(Date date)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from ww w.ja v a2 s .c o m * Expanded ISO 8601 Date format yyyy-MM-dd i.e., 2002-12-25 for the 25th day of December in the year 2002 */ public static final String ISO_EXPANDED_DATE_FORMAT = "yyyy-MM-dd"; /** * yyyy-MM-dd hh:mm:ss */ public static String DATETIME_PATTERN = "yyyy-MM-dd hh:mm:ss"; public static String dateToStringWithTime(Date date) { return dateToString(date, DATETIME_PATTERN); } public static String dateToString(Date date, String pattern) { if (date == null) { return null; } try { SimpleDateFormat sfDate = new SimpleDateFormat(pattern); sfDate.setLenient(false); return sfDate.format(date); } catch (Exception e) { return null; } } public static String dateToString(Date date) { return dateToString(date, ISO_EXPANDED_DATE_FORMAT); } }