且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

乔达时间 - 时区之间不同

更新时间:2023-11-29 12:19:58


我想用Joda时间将当前时间转换为特定时区的时间。 p>

目前还没有确定您是否已经获得,这并不清楚。如果您已经有了,可以使用 withZone

  DateTime zoned = original.withZone(zone); 

如果您只是获取当前时间,请使用适当的构造函数

  DateTime zoned = new DateTime(zone); 

或使用 DateTime.now

  DateTime zoned = DateTime.now(zone); 


I want to convert the current time to the time in a specific timezone with Joda time.

Is there a way to convert DateTime time = new DateTime() to a specific timezone, or perhaps to get the number of hours difference between time.getZone() and another DateTimeZone to then do time.minusHours or time.plusHours?

I want to convert the current time to the time in a specific timezone with Joda time.

It's not really clear whether you've already got the current time or not. If you've already got it, you can use withZone:

DateTime zoned = original.withZone(zone);

If you're just fetching the current time, use the appropriate constructor:

DateTime zoned = new DateTime(zone);

or use DateTime.now:

DateTime zoned = DateTime.now(zone);