java – joda-time:new DateTime(String)vs DateTime. parse(String)

Using the joda-time-2.0 version library, I want to know which function is more suitable for building from ISO date (updated XML XS: datetime format): new datetime (string) and datetime parse(String).

Because both return different results from the same value Example:

new DateTime("2012-08-16T07:22:05Z")
DateTime.parse("2012-08-16T07:22:05Z")

Because isochronology leads to different The first is isochronology [Europe / Paris] and the second isochronology [UTC], although milliseconds are the same

In addition, here recommends using isodatetimeformat Datetimenomillis() gives the same result as using the first version (New)

Solution

The two methods use two different conversion methods: the constructor uses an instance of instantconverter, which is a stringconverter in the case of a string, and does not support reading the time zone from the passed string, while the parsing method uses datetimeformatter to know how to parse the time zone

Although both formats theoretically accept the ISO date time format, I think the constructor is wrong because it always uses the system time zone rather than the time zone specified in the string This is inconsistent with other possible values accepted by this constructor, which do take into account the chronological order with time zone offset For example, this constructor will return a datetime object with a UTC time zone:

new DateTime(DateTime.parse("2012-08-16T07:22:05Z"))
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>