Here you can find the source of toString(Date now)
public static String toString(Date now)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** yyyy-MM-dd HH:mm:ss */ public static final String PATNER_DEFAULT = "yyyy-MM-dd HH:mm:ss"; public static String toString(Date now) { SimpleDateFormat formatTime = new SimpleDateFormat(PATNER_DEFAULT); if (now == null) return ""; return formatTime.format(now); }/*from w w w. java 2 s .co m*/ public static String format(Date date, String formatter) { SimpleDateFormat formatTime = new SimpleDateFormat(formatter); return formatTime.format(date); } }