About Question enthuware.ocpjp.v8.2.1760 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
adrian
Posts: 2
Joined: Sat Jul 11, 2020 4:54 am
Contact:

About Question enthuware.ocpjp.v8.2.1760 :

Post by adrian »

Hi,

I have found this question in your mock exam:

Code: Select all

	Instant start = Instant.parse("2015-06-25T16:13:30.00z");
		start.plus(10, ChronoUnit.HOURS);
		System.out.println(start);

		Duration timeToCook = Duration.ofHours(1);
		Instant readyTime = start.plus(timeToCook);
		System.out.println(readyTime);

		LocalDateTime ltd = LocalDateTime.ofInstant(readyTime, ZoneId.of("GMT-2"));
		System.out.println(ltd);
And the result is
2015-06-25T16:13:30Z
2015-06-25T17:13:30Z
2015-06-25T15:13:30
First 2 lines of output are as expected for me.
What I do not understand is the last line of output. I know that always you should subtract the offset time zone from the actual time. So if your offset is negative you will add (- * - = +) the offset and if the offset is positive you will subtract (- * + = -).

In this case the offset is negative so from my point of view we should add 2 hr to our final result and to get 19:13:20 and not 15:13:30

What I am missing here?

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1760 :

Post by admin »

> I know that always you should subtract the offset time zone from the actual time.
Not sure where you read that or in what context was it written.

Instant returns a represents the machine view of time. Since a computer only cares about the number of milliseconds that have elapsed since Epoch. That is what an Instant contains. It has no notion of AM/PM or time zone. It is a point on the machine view of the timeline. This machine view actually corresponds to UTC (which is, technically, same at GMT+0).

Now, when you try to create a LocalDateTime using an Instant by specifying a time zone to the Instant, you are basically trying to find the time in that zone at that instant. So, if your time zone is GMT+2, the local time at that instant in that zone is UTC+2. If your time zone is GMT-2, then the localdatetime at that instant in that zone is UTC-2.

GMT-2 means, your timezone is 2 hours behind GMT. So, if your Instant is 17.13 (which is UTC), then the time in the GMT-2 zone is, obviously, 15.13 (because it is two hours behind).
If you like our products and services, please help us by posting your review here.

adrian
Posts: 2
Joined: Sat Jul 11, 2020 4:54 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1760 :

Post by adrian »

I am also reading OCP by Jeanne Boyarsky and Scott Selikoff. Here is where I have read that but I am guessing that this is for timezone because what I have write about Instant makes perfect sens.
Image

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1760 :

Post by admin »

Every author has their own way of explaining things. If you find the above text easier to understand, that's fine. As long as you are able to make a mental picture of the concept and are able to solve the given problem, it should be ok.

Personally, I find the above text highly confusing, "To approach a problem like this, you subtract the time zone from the time." Subtract time zone from which time? What are these two times? Do they have any relation? Why is the text talking about these?
2015–06–20T07:50+02:00[Europe/Paris] // GMT 2015–06–20 5:50
2015–06–20T06:50+05:30[Asia/Kolkata] // GMT 2015–06–20 1:20

"Remember that you need to add when subtracting a negative number." - I honestly don't find this statement helpful at all. It is causing more confusion. But again, that is my personal view.


Also, this text has nothing to do with Instant (which is what the question is about). Instant is a completely different animal from Date and Time. Has the text explained the difference between them clearly? Have you understood it?

>> because what I have write about Instant makes perfect sens.
If you are able to get the right answer using your logic, then that's good. If not, then you may have to rethink.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 190 guests