Convert timestamp long to normal date format

前端 未结 5 1443
南旧
南旧 2020-12-09 03:46

In my web app, date & time of a user\'s certain activity is stored(in database) as a timestamp Long which on being displayed back to user needs to be conver

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 04:32

    Not sure if JSF provides a built-in functionality, but you could use java.sql.Date's constructor to convert to a date object: http://download.oracle.com/javase/1.5.0/docs/api/java/sql/Date.html#Date(long)

    Then you should be able to use higher level features provided by Java SE, Java EE to display and format the extracted date. You could instantiate a java.util.Calendar and explicitly set the time: http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html#setTime(java.util.Date)

    EDIT: The JSF components should not take care of the conversion. Your data access layer (persistence layer) should take care of this. In other words, your JSF components should not handle the long typed attributes but only a Date or Calendar typed attributes.

提交回复
热议问题