How to convert Date.toString back to Date?

后端 未结 5 1487
礼貌的吻别
礼貌的吻别 2020-11-27 07:24

I have a string obtained by calling the toString method of instance of the class Date.
How can I get a Date object from this string?

Date d          


        
5条回答
  •  误落风尘
    2020-11-27 07:49

    If your real goal is to serialize a Date object for some kind of custom made persistence or data transfer, a simple solution would be:

    Date d = new Date();
    long l = d.getTime();
    Date theSameDate = new Date(l);
    

提交回复
热议问题