Here you can find the source of toDateTime(Date date)
public static String toDateTime(Date date)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static String toDateTime(Date date) { return toDateTime(date, DEFAULT_DATE_TIME_FORMAT); }/*from www.jav a2 s . com*/ public static String toDateTime(Date dateTime, String pattern) { pattern = pattern == null ? "yyyy-MM-dd HH:mm:ss" : pattern; SimpleDateFormat format = new SimpleDateFormat(pattern); String datastring = format.format(dateTime); return datastring; } }