In joda time how to convert time zone without changing time

后端 未结 7 1973
一生所求
一生所求 2020-12-04 19:06

I am getting UTC timestamp from database which is I am setting into a JodaTime DateTime instance

DateTime dt = new DateTime(timestamp.getTime())         


        
7条回答
  •  有刺的猬
    2020-12-04 19:34

    You can use class LocalDateTime

    LocalDateTime dt = new LocalDateTime(t.getTime()); 
    

    and convert LocalDateTime to DateTime

    DateTime dt = new LocalDateTime(timestamp.getTime()).toDateTime(DateTimeZone.UTC);  
    

    Joda DateTime treats any time in millis like "millis since 1970y in current time zone". So, when you create DateTime instance, it is created with current time zone.

提交回复
热议问题