且构网

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

使用java转换日期更快的时区

更新时间:2023-11-29 12:41:16

使用 joda-time 可能如下所示:

DateTime dt = new DateTime(DateTimeZone.forID("GMT"));
System.out.println(dt); // 5 am
dt = dt.withZone(DateTimeZone.forID("EET"));
System.out.println(dt); // 8 am

请注意, Timestamp 没有时区的概念,所以它不适合代表它。

Note that Timestamp has no notion of Timezone so it is not suitable for representing it.

您的解决方案将具有良好的运行时间,因为它是O(1)。很难阅读。

Your solution will have a good running time, since it's O(1). It's harder to read though.