Purpose of Joda Time LocalDate(Object instant, DateTimeZone zone) constructor

Joda Time's LocalDate describe itself as:

LocalDate is an immutable datetime class representing a date without a time zone.

Yet there is a LocalDate(Object instant, DateTimeZone zone) constructor that accepts time zone. If the object is time zone-less, what's the purpose of the time zone constructor?

The constructor JavaDocs states:

Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.

I don't know what is meant by "forcing the time zone to that specified", since the object is time zone-less. Perhaps it internally converts to UTC, then drops the time (keeps the date).


You cannot convert from an instant to a local date or time without knowing the time-zone (or at least the offset from UTC/Greenwich). Since the first argument is an instant (such as Long or java.util.Date , the second argument is needed to specify the time-zone to use.

Note that there is also a constructor LocalDate(Object) which uses the default time-zone internally.


An instant is a concept from the realm of physics. It's a point in time , well defined, regardless of how you represent it. It's has nothing to do -conceptually- with timezones, calendars, or whatever conventions of human culture.

Examples: the moment when the Apollo XI landed on Moon, or the moment when J. Kennedy was shot, are instants. Each of these could be represented in several ways: a Julian calendar, seconds lapsed from the moment when the Titanic hit the iceberg, some calendar used by some extraterrestial being who lives in Mars... all these would be different representations, but the instant would be a single one (just like 1903 , 0x76F or MCMIII are different representations of the same number).

Now, if you want to convert the "instant of Apollo XI moon landing" to a LocalDate (a day-month-year, as used in Gregorian calendars in Earth), you are going to a totally different realm, and -for one thing- you need to know the timezone, because in some countries that instant (July 20, 1969, 20:17:40 UTC) corresponds to July 20, 1969, in others to July 21


You should read the whole JavaDoc:

If the object contains no chronology, ISOChronology is used. If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.

The recognised object types are defined in ConverterManager and include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described by ISODateTimeFormat.localDateParser(). The default String converter ignores the zone and only parses the field values.

This way the representations of date (String, Calendar, Date, etc.) together with the specified time zone give you the local time.

If for example you have a java.util.Date representation of date then it's local time depends on the time zone. By specifying the time zone you define the local time.

链接地址: http://www.djcxy.com/p/18522.html

上一篇: 时间DateMidnight

下一篇: Joda时间LocalDate(对象即时,DateTimeZone区域)构造函数的用途