I plan to convert ZonedDateTime to instant, as shown below.
Say I'm in PST timeZone and the current time is 11A.M. If I convert now (without daylight from today March 4, 2018), and toInstant will be 7 PM
For the same 11 AM, toInstant will return 6 PM as of April 4, 2018, when daylight saving time will be observed.
So, the code below is returned correctly.
ZonedDateTime dateTime = ZonedDateTime.now(); --->>> March 04th 2018 at 11 A.M PST
dateTime.plusMonths(1).toInstant(); -->> returns April 04th 2018 at 6 PM PST as daylight saving will be observed
But,
The result will be different if I convert to Instant and then add a month.
Instant dateTime = ZonedDateTime.now().toInstant();
dateTime.plus(1,ChronoUnit.MONTHS).toInstant();
This is normal, as we have already converted to UTC, and it just adds from there.
Therefore, to enable daylight saving time, I need to add days, months or years .... to ZonedDateTime, and then convert to Instant.
ZonedDateTime dateTime = ZonedDateTime.now();
dateTime.plusDays(10).toInstant();
dateTime.plusMonths(1).toInstant();
, . 6 P.M, 7 P.M.
dateTime.plusSeconds(org.joda.time.Period.days(1).multipliedBy(10).toStandardSeconds().getSeconds())
.toInstant()) --> ---> March 14th 2018 at 7P.M
, .