简体   繁体   中英

Joda-time: convert jodaTime with timezone

Please help me with this case:

  1. pick a date from front-end, like 3/8/2016 05:53:00
  2. A user's timeZone is GMT-08:00, plus with 8 hours, save it to DB as 3/8/2016 13:53:00
  3. B user's timeZone is GMT-10:00, plus with 10 hours, save it to DB as 3/8/2016 15:53:00
  4. A and will see 3/8/2016 05:53:00 on page after we convert the date from Database.

I think we can write a util to convert datetime, plus or minus it. Is there a stand way to implement it?

Pick the date and add the times one for the conversion. All the Joda timezones are here :

Example:

final DateTime dt = new DateTime();
// translate to Honolulu local time
final DateTime dtVancouver = dt.withZone(DateTimeZone.forID("Etc/GMT+8"));
final DateTime dtHonolulu = dt.withZone(DateTimeZone.forID("Etc/GMT+10"));
System.out.println(dt);
System.out.println(dtVancouver);
System.out.println(dtHonolulu);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM