How to format a java.sql Timestamp for displaying?

前端 未结 7 1858
借酒劲吻你
借酒劲吻你 2020-12-12 20:13

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

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 20:44

    If you're using MySQL and want the database itself to perform the conversion, use this:

    DATE_FORMAT(date,format)

    If you prefer to format using Java, use this:

    java.text.SimpleDateFormat

    SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy");
    dateFormat.format( new Date() );
    

提交回复
热议问题