Here you can find the source of dateTimeToString(Timestamp dt, String df)
public static String dateTimeToString(Timestamp dt, String df)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.SimpleDateFormat; public class Main { /**/*from ww w .j ava 2 s . com*/ * DateTime convert to String. * * @return String representation of the given DateTime and DateFormat. */ public static String dateTimeToString(Timestamp dt, String df) { String pstrDate = null; // return value if (dt == null) { return ""; } String formatStyle = null; if ((df == null) || (df.equals(""))) { formatStyle = "yyyy-MM-dd HH:mm:ss"; } else { formatStyle = df; } SimpleDateFormat oFormatter = null; try { oFormatter = new SimpleDateFormat(formatStyle); pstrDate = oFormatter.format(formatStyle); } catch (Exception e) { oFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); pstrDate = oFormatter.format(dt); } return pstrDate; } }