Convert String to java.util.Date

后端 未结 4 496
猫巷女王i
猫巷女王i 2020-11-27 18:46

I am storing the dates in a SQLite database in this format:

d-MMM-yyyy,HH:mm:ss aaa

When I retrieve the date with that format I am get ever

4条回答
  •  佛祖请我去吃肉
    2020-11-27 19:21

    It sounds like you may want to use something like SimpleDateFormat. http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

    You declare your date format and then call the parse method with your string.

    private static final DateFormat DF = new SimpleDateFormat(...);
    Date myDate = DF.parse("1234");
    

    And as Guillaume says, set the timezone!

提交回复
热议问题