JodaTime - how to get current time in UTC

前端 未结 7 559
天命终不由人
天命终不由人 2020-12-14 01:12

I want to get the current time in UTC. What I do so far is following (just for testing purposes):

    DateTime dt = new DateTime();
    DateTimeZone tz = Dat         


        
7条回答
  •  独厮守ぢ
    2020-12-14 01:57

    From here: http://www.joda.org/joda-time/userguide.html#Changing_TimeZone

    // get current moment in default time zone
    DateTime dt = new DateTime();
    // translate to London local time
    DateTime dtLondon = dt.withZone(DateTimeZone.forID("Europe/London"));
    

    The resulting value dtLondon has the same absolute millisecond time, but a different set of field values.

    You can substitute `Europe/London' for the timezone you want (UTC). See this list of proper time zone names.

提交回复
热议问题