Here you can find the source of getDateTimeString(java.sql.Timestamp ts)
public static String getDateTimeString(java.sql.Timestamp ts)
//package com.java2s; public class Main { public static String getDateTimeString(java.sql.Timestamp ts) { if (ts == null) { return ""; }//from ww w.ja v a 2 s . c o m return Timestamp2DDMMYYYY(ts) + " " + Timestamp2HHMMSS(ts, 1); } public static String Timestamp2DDMMYYYY(java.sql.Timestamp ts) { if (ts == null) { return ""; } else { java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(new java.util.Date(ts.getTime())); String strTemp = Integer.toString(calendar.get(calendar.DAY_OF_MONTH)); if (calendar.get(calendar.DAY_OF_MONTH) < 10) { strTemp = "0" + strTemp; } if (calendar.get(calendar.MONTH) + 1 < 10) { return strTemp + "/0" + (calendar.get(calendar.MONTH) + 1) + "/" + calendar.get(calendar.YEAR); } else { return strTemp + "/" + (calendar.get(calendar.MONTH) + 1) + "/" + calendar.get(calendar.YEAR); } } } public static String Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle) { if (ts == null) { return ""; } java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(new java.util.Date(ts.getTime())); String strTemp; if (iStyle == 0) { strTemp = Integer.toString(calendar.get(calendar.HOUR_OF_DAY)); } else { strTemp = Integer.toString(calendar.get(calendar.HOUR_OF_DAY)); } if (strTemp.length() < 2) { strTemp = "0" + strTemp; } if (calendar.get(calendar.MINUTE) < 10) { strTemp += ":0" + calendar.get(calendar.MINUTE); } else { strTemp += ":" + calendar.get(calendar.MINUTE); } if (calendar.get(calendar.SECOND) < 10) { strTemp += ":0" + calendar.get(calendar.SECOND); } else { strTemp += ":" + calendar.get(calendar.SECOND); } if (iStyle != 0) { if (calendar.get(calendar.AM_PM) == calendar.AM) { strTemp += " AM"; } else { strTemp += " PM"; } } return strTemp; } }