Here you can find the source of timestamp2Str(Timestamp time, String format)
public static String timestamp2Str(Timestamp time, String format)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String PATTERN_YMDHMS = "yyyy-MM-dd HH:mm:ss"; public static String timestamp2Str(Timestamp time, String format) { Date date = null;/* ww w. j a v a2 s .c o m*/ if (null != time) { if (format == null) { format = PATTERN_YMDHMS; } date = new Date(time.getTime()); } return dateToString(date, format); } public static String dateToString(Date inputDateTime, String format) { String outDateTime = "0000-00-00 00:00:00"; try { SimpleDateFormat formatter = new SimpleDateFormat(format); outDateTime = formatter.format(inputDateTime); } catch (Exception ex) { } return outDateTime; } }