Obtains an instance of ZonedDateTime from a year, month, day,
hour, minute, second, nanosecond and time-zone.
This creates a zoned date-time matching the local date-time of the seven specified fields as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may be adjusted.
The local date-time is resolved to a single instant on the time-line.
This is achieved by finding a valid offset from UTC/Greenwich for the local
date-time as defined by the rules of the zone ID.
In most cases, there is only one valid offset for a local date-time. In the case of an overlap, when clocks are set back, there are two valid offsets. This method uses the earlier offset typically corresponding to "summer".
In the case of a gap, when clocks jump forward, there is no valid offset. Instead, the local date-time is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the local date-time will be moved one hour later into the offset typically corresponding to "summer".
This method exists primarily for writing test cases.
Non test-code will typically use other methods to create an offset time.
LocalDateTime has five additional convenience variants of the
equivalent factory method taking fewer arguments.
They are not provided here to reduce the footprint of the API.
year | the year to represent, from MIN_YEAR to MAX_YEAR | |
month | the month-of-year to represent, from 1 (January) to 12 (December) | |
dayOfMonth | the day-of-month to represent, from 1 to 31 | |
hour | the hour-of-day to represent, from 0 to 23 | |
minute | the minute-of-hour to represent, from 0 to 59 | |
second | the second-of-minute to represent, from 0 to 59 | |
nanoOfSecond | the nano-of-second to represent, from 0 to 999,999,999 | |
zone | the time-zone, not null |
DateTimeException | if the value of any field is out of range, or if the day-of-month is invalid for the month-year |
Diagram: ZonedDateTime