How to convert Date.toString back to Date?

后端 未结 5 1468
礼貌的吻别
礼貌的吻别 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:34

    Date theSameDate = new Date(Date.parse(s));

    For some not so obvious reasons, this is not a particularly good idea. You can find details on that in the API documentation for the parse method. One problem is e.g. that the time zone abbreviations are ambiguous, so that the parser may fail in interpreting the correct time zone.

提交回复
热议问题