I see. Thank you.admin wrote:Time zone is same i.e. US/Eastern. Daylight start or end doesn't change the time zone. Only the zone offset wrt to GMT depends on whether dst is on or off.
About Question enthuware.ocpjp.v8.2.1749 :
Moderator: admin
-
- Posts: 106
- Joined: Mon Mar 28, 2016 11:36 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
-
- Posts: 4
- Joined: Fri Sep 30, 2016 4:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Program does not compiles . As per i know for comparision zoneddatetime must be converted into instant to remove timezone...
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
Please try the exact code that is given it the question. It compiles and runs fine.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 7
- Joined: Wed Jun 25, 2014 12:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I think it is always good to pick the time that is before the DST when one is before DST and another is after DST. In this case it is LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) and LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0) respectively.
Then, add up 1 hour at a time to the time (which is before DST ) in order to reach the other time after DST.
so add 1 more to the above result:
we add 2 hours in total to get to the other time.
See here: http://tpcg.io/LUCsMp
Then, add up 1 hour at a time to the time (which is before DST ) in order to reach the other time after DST.
Code: Select all
LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) + 1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0) which becomes LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0)
Code: Select all
(LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 0) + 1) + 1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0)
See here: http://tpcg.io/LUCsMp
-
- Posts: 11
- Joined: Sun Mar 18, 2018 9:08 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
To be honest, I don't care much for this question. It assumes knowledge how Java will behave when you set it 1AM on the day the clocks go back. On that day we have two 1AMs. How does Java know which one we are referring to when we set the time?
If it were the 2nd 1AM then the time difference would only be 1 hour. It would have been less ambiguous if it was 12:59am to 2PM. Then we could say without a doubt that it'll take 2 hours and 1 minute. It seems like it's testing us on a very specific and rare corner case. Although.. if the test-makers at Oracle write questions like this it'll be good practice for us. But even in that case I would argue that they designed the question poorly.
Again, just my two cents. It's not like it's important or anything.
If it were the 2nd 1AM then the time difference would only be 1 hour. It would have been less ambiguous if it was 12:59am to 2PM. Then we could say without a doubt that it'll take 2 hours and 1 minute. It seems like it's testing us on a very specific and rare corner case. Although.. if the test-makers at Oracle write questions like this it'll be good practice for us. But even in that case I would argue that they designed the question poorly.
Again, just my two cents. It's not like it's important or anything.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
I have been playing around with this and what seems to be the case is that when the clocks go back, java sees any time before 2am as "pre-DST change" and any time from 2am onwards as "post-DST change":
Please correct me if I'm wrong.
Code: Select all
LocalDateTime ld1 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 59);
ZonedDateTime zd1 = ZonedDateTime.of(ld1, ZoneId.of("US/Eastern"));
LocalDateTime ld2 = LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 0);
ZonedDateTime zd2 = ZonedDateTime.of(ld2, ZoneId.of("US/Eastern"));
long m = ChronoUnit.MINUTES.between(zd1, zd2); System.out.println(m); //61
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
That sounds correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
To grasp this concept fully you have to understand, that if it already is 2 am in LocalDateTime, then the time change already happened. The clock is NOT turned back to 1 am!
2 am stays 2 am and now the question is how long does it take to go from 1 am to 2 am considering the time change. It takes, of course, 2 hours.
2 am stays 2 am and now the question is how long does it take to go from 1 am to 2 am considering the time change. It takes, of course, 2 hours.
-
- Posts: 1
- Joined: Thu May 30, 2019 8:16 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1749 :
in Poland we change time Zone from CET - Central European Time (GMT+1) to CEST - Central European Sumer Time (GMT+2). this is very confusing that they using the same name for difrent Zone. If they change time zone, they should use difrent time zone name, but stil have the same offset from GMT.
how did they know on witch 1:01 AM they have? before or after change to summer time?
how did they know on witch 1:01 AM they have? before or after change to summer time?
Who is online
Users browsing this forum: No registered users and 83 guests