How to handle jodatime Illegal instant due to time zone offset transition

前端 未结 5 1869
無奈伤痛
無奈伤痛 2020-12-08 13:42

I want to set up joda DateTime to today at 2 AM (see sample code below). But I\'m getting this exception:

Exception in thread \"main\" org.joda.         


        
5条回答
  •  我在风中等你
    2020-12-08 14:12

    CET switches to DST (summer time) on the last Sunday in March, which happens to be today. The time went from 1:59:59 to 3:00:00 – there's no 2, hence the exception.

    You should use UTC instead of local time to avoid this kind of time zone issue.

    MutableDateTime now = new MutableDateTime(DateTimeZone.UTC);
    

提交回复
热议问题