Joda Time - different between timezones

前端 未结 2 1145
梦谈多话
梦谈多话 2020-12-10 14:23

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 spec

2条回答
  •  死守一世寂寞
    2020-12-10 15:24

    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);
    

提交回复
热议问题