How can I convert a Timestamp into either Date or DateTime object?

前端 未结 4 923
攒了一身酷
攒了一身酷 2020-12-15 06:06

I\'m retrieving a timestamp object from a database using ResultSet.getTimestamp(), but I\'d like an easy way to get the date in the format of MM/DD/YYYY

4条回答
  •  一生所求
    2020-12-15 06:30

    java.sql.Timestamp is a subclass of java.util.Date. So, just upcast it.

    Date dtStart = resultSet.getTimestamp("dtStart");
    Date dtEnd = resultSet.getTimestamp("dtEnd");
    

    Using SimpleDateFormat and creating Joda DateTime should be straightforward from this point on.

提交回复
热议问题