Joda DateTime: Parse date with “CEST” in string

后端 未结 2 1412
遇见更好的自我
遇见更好的自我 2020-12-21 11:33

I want to parse a DateTime using the joda library (in scala, but should be the same with java).

The source looks like

val dateParser = DateTimeFormat         


        
2条回答
  •  清酒与你
    2020-12-21 12:15

    Apply parsing with a java.util.Dateinstance allows you to apply a workaround since CEST is not well parsing since not unique:

    DateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    DateTime dateTime = new DateTime(dateParser.parse("2012-08-28 15:35:00 CEST"));
    //Here parsed `java.util.Date` instance is back to an instance of org.jodatime.DateTime`
    

    Benefit of this workaround: to not bother with "which version works with this timezone???"

提交回复
热议问题