About Question enthuware.ocpjp.v8.2.2018 :
Moderator: admin
-
- Posts: 5
- Joined: Fri Mar 10, 2017 12:25 pm
- Contact:
About Question enthuware.ocpjp.v8.2.2018 :
I think the answer should be PT-3H since new york time is always ahead by 3 hours and we are doing Duration.between(newYorkTime, losAngelesTime)
example -
LocalDateTime losAngelesTime = LocalDateTime.of(2017, 1, 10,6,30); //LA
LocalDateTime newYorkTime = LocalDateTime.of(2017, 1, 10, 9, 30); //NY
System.out.println(Duration.between(losAngelesTime, newYorkTime )); //PT3H
System.out.println(Duration.between(newYorkTime, losAngelesTime )); //PT-3H
example -
LocalDateTime losAngelesTime = LocalDateTime.of(2017, 1, 10,6,30); //LA
LocalDateTime newYorkTime = LocalDateTime.of(2017, 1, 10, 9, 30); //NY
System.out.println(Duration.between(losAngelesTime, newYorkTime )); //PT3H
System.out.println(Duration.between(newYorkTime, losAngelesTime )); //PT-3H
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
No, NY is ahead of LA. So it will be +3 and not -3.
Please check https://docs.oracle.com/javase/8/docs/a ... .Temporal- for details.
Please check https://docs.oracle.com/javase/8/docs/a ... .Temporal- for details.
The result of this method can be a negative period if the end is before the start.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Mon Aug 24, 2015 4:40 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Still don`t understand your answer.
Doesn`t "NY is ahead of LA" mean that time in NY is greater than in LA by 3 hours?
i.e.
NY 9:30 AM
LA 6:30 AM
Doesn`t "NY is ahead of LA" mean that time in NY is greater than in LA by 3 hours?
i.e.
NY 9:30 AM
LA 6:30 AM
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Right. So NY minus LA will be +3, right?aceoftrumps wrote:Still don`t understand your answer.
Doesn`t "NY is ahead of LA" mean that time in NY is greater than in LA by 3 hours?
i.e.
NY 9:30 AM
LA 6:30 AM
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sat Jun 03, 2017 11:11 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
deleted
Last edited by sedletskiyv on Thu Jun 15, 2017 6:36 am, edited 1 time in total.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
The JavaDoc for this method clearly says that the result of this method is a negative period if the end is before the start.
Here, end i.e. LA is NOT before start i.e. NY.
LA is after NY.
So I am not sure why you are expecting the result to be negative.
Paul.
Here, end i.e. LA is NOT before start i.e. NY.
LA is after NY.
So I am not sure why you are expecting the result to be negative.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sat Jun 03, 2017 11:11 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Thanks, I think the correct logic here is "6 a.m. in LA will happen 3 hours after the 6 a.m. happens in NY" - that's why PT3H.admin wrote:The JavaDoc for this method clearly says that the result of this method is a negative period if the end is before the start.
Here, end i.e. LA is NOT before start i.e. NY.
LA is after NY.
So I am not sure why you are expecting the result to be negative.
Paul.
I was misled by an incorrect example at the top post:
LocalDateTime losAngelesTime = LocalDateTime.of(2017, 1, 10,6,30); //LA
LocalDateTime newYorkTime = LocalDateTime.of(2017, 1, 10, 9, 30); //NY
System.out.println(Duration.between(newYorkTime, losAngelesTime )); //PT-3H
-
- Posts: 1
- Joined: Sat Aug 12, 2017 4:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
This question is wrong. When you say "3 hours ahead", it means if it is 10:00 in LA then it will be 13:00 in NY. For people who live in the USA it might be easy to figure the question didn't actually meant 3 hour ahead but +3 on on LA's time zone. If what you mean is +3 on time zone than you need to inform that LA is GMT-8 otherwise everyone will assume you are talking about time and not time zone.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
This is the terminology used by the questions in the real exam. It means exactly what it says. NY is indeed ahead of LA by 3 hours.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Sat Jan 20, 2018 12:06 pm
Re: About Question enthuware.ocpjp.v8.2.2018 :
why not LA - NY? why you subtract the other way? can you explain cause it is very confusing!admin wrote:Right. So NY minus LA will be +3, right?aceoftrumps wrote:Still don`t understand your answer.
Doesn`t "NY is ahead of LA" mean that time in NY is greater than in LA by 3 hours?
i.e.
NY 9:30 AM
LA 6:30 AM
take a look at similar example
Code: Select all
Instant now = Instant.now();
Thread.sleep(100);
Instant later = Instant.now();
System.out.println(now);
System.out.println(later);
System.out.println(Duration.between(now, later).toMillis());
Code: Select all
2018-02-04T14:14:16.652Z
2018-02-04T14:14:16.764Z
112
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Well, did you read the complete thread above?
If NY is ahead of LA then at any given instant, the local time at NY will be later than the local time at LA. For example, if it is 1PM in LA then it will be 4PM in NY at that very instant.
In your example also, end is not before start, so why would you expect a negative number?
Please go through the thread above carefully and also read the JavaDoc API description of Duration.between method.
If NY is ahead of LA then at any given instant, the local time at NY will be later than the local time at LA. For example, if it is 1PM in LA then it will be 4PM in NY at that very instant.
In your example also, end is not before start, so why would you expect a negative number?
Please go through the thread above carefully and also read the JavaDoc API description of Duration.between method.
If you like our products and services, please help us by posting your review here.
-
- Posts: 11
- Joined: Sun Mar 18, 2018 9:08 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
I got messed up by this one too, but I figured it out. I think the confusion comes from the explanation.
The question says NY is 3 hours ahead of LA so that's why we start thinking "It's 3 hours later, so.. we have to go back in time 3 hours to get to LA"
But.. The time is 6am in both places, only the time zone changes. 6am in NY on any given day happens 3 hours before 6am in LA. So this: Duration d = Duration.between(nyZdt, laZdt); means starting at 6am in NY how long does it take until it's 6am in LA. 3 hours.
That's why we have practice tests with explanations.. lol.
The question says NY is 3 hours ahead of LA so that's why we start thinking "It's 3 hours later, so.. we have to go back in time 3 hours to get to LA"
But.. The time is 6am in both places, only the time zone changes. 6am in NY on any given day happens 3 hours before 6am in LA. So this: Duration d = Duration.between(nyZdt, laZdt); means starting at 6am in NY how long does it take until it's 6am in LA. 3 hours.
That's why we have practice tests with explanations.. lol.
-
- Posts: 11
- Joined: Fri Aug 17, 2018 8:52 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Thank you, Wesley!!!
This was very confussing but now I got it thanks to you
This was very confussing but now I got it thanks to you
-
- Posts: 25
- Joined: Thu Jun 01, 2017 2:50 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
I also find descriptions of time differences potentially confusing, and got this wrong during the test. In case it helps anyone still studying for this exam and still unsure after reading the above discussions, here's the way I thought about it reviewing afterwards (just different words for same explanations):
Both will say 6am, but the LA 6am will be 3 hours farther along in universal time than NY; confirmed this by printing Instant equivalents below...
Both will say 6am, but the LA 6am will be 3 hours farther along in universal time than NY; confirmed this by printing Instant equivalents below...
Code: Select all
LocalDateTime ldt = LocalDateTime.of(2017, 12, 02, 6, 0, 0);
// --I added the following declarations to define the nyZone and laZone variables below
ZoneId nyZone = ZoneId.of("US/Eastern");
ZoneId laZone = ZoneId.of("US/Pacific");
ZonedDateTime nyZdt = ldt.atZone(nyZone);
ZonedDateTime laZdt = ldt.atZone(laZone);
Duration d = Duration.between(nyZdt, laZdt);
System.out.println(d); // PT3H
// I added to view time representations...
System.out.println(nyZdt); // 2017-12-02T06:00-05:00[US/Eastern]
System.out.println(laZdt); // 2017-12-02T06:00-08:00[US/Pacific]
// ...and converting to Instant, will see LA time is 3 hours later...
System.out.println(nyZdt.toInstant()); // 2017-12-02T11:00:00Z -- 11:00 hours (5 hours later than GMT/UTC)
System.out.println(laZdt.toInstant()); // 2017-12-02T14:00:00Z -- 14:00 hours (8 hours later than GMT/UTC)
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Thank you for sharing your perspective. Different people grasp concepts differently and your perspective will definitely help some people make sense of this.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Fri Apr 30, 2021 8:47 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2018 :
Hi Guys,
This question is brilliant, it got me good I answered PT-3H. This question it does not asses you on the time between the two city's it asses you on the zone id of the two city's, to understand this question you must understand how time zone works. Time Zone Map . I added an extra zone id from Europe which is Bucharest just to have a positive number.
Here is how this code works:
The question states: "Given that New York is 3 hours ahead of Los Angeles, what will the following code print?"
A LocalDateTime is created and given a custom date and time (2017, 12, 02, 6, 0, 0).
The zone id's are:
New York -> date 02/12/2017, time 6:00. Remember custom LocalDateTime.of(2017, 12, 02, 6, 0, 0) and zone id -5.
Los Angeles -> date 02/12/2017, time 3:00 because New York's time is ahead of Los Angeles time by 3 hours, zone id -8.
Bucharest -> date of 02/12/2017, time 11:00 because Bucharest its ahead of New York by 7 hours, zone id +2.
When the arguments are passed to between() method behind the scene a subtraction of the zone id's is made(nyZdt - laZdt).
This question is brilliant, it got me good I answered PT-3H. This question it does not asses you on the time between the two city's it asses you on the zone id of the two city's, to understand this question you must understand how time zone works. Time Zone Map . I added an extra zone id from Europe which is Bucharest just to have a positive number.
Here is how this code works:
The question states: "Given that New York is 3 hours ahead of Los Angeles, what will the following code print?"
A LocalDateTime is created and given a custom date and time (2017, 12, 02, 6, 0, 0).
The zone id's are:
New York -> date 02/12/2017, time 6:00. Remember custom LocalDateTime.of(2017, 12, 02, 6, 0, 0) and zone id -5.
Los Angeles -> date 02/12/2017, time 3:00 because New York's time is ahead of Los Angeles time by 3 hours, zone id -8.
Bucharest -> date of 02/12/2017, time 11:00 because Bucharest its ahead of New York by 7 hours, zone id +2.
When the arguments are passed to between() method behind the scene a subtraction of the zone id's is made(nyZdt - laZdt).
- Attachments
-
- 2021-04-30 (1).png (71.11 KiB) Viewed 4610 times
Who is online
Users browsing this forum: pavvel and 99 guests