Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static String date2String(Date date) { return date2String(date, DEFAULT_PATTERN); } public static String date2String(Date date, String pattern) { return new SimpleDateFormat(pattern, Locale.getDefault()).format(date); } }