Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

java - Joda Time - different between timezones

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...