How to format a java.sql Timestamp for displaying?

nos picture nos · Jul 21, 2009 · Viewed 266.2k times · Source

How do I formate a java.sql Timestamp to my liking ? ( to a string, for display purposes)

Answer

ChssPly76 picture ChssPly76 · Jul 21, 2009

java.sql.Timestamp extends java.util.Date. You can do:

String s = new SimpleDateFormat("MM/dd/yyyy").format(myTimestamp);

Or to also include time:

String s = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(myTimestamp);