• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Working with time zones in Ch. 5

 
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is related to the materials from Ch. 5 of this hard copy book: https://www.amazon.com/OCP-Certified-Professional-Programmer-1Z0-809/dp/1119067901?ie=UTF8&*Version*=1&*entries*=0

On Page 236 of the hard copy book of Ch. 5, there are code snippets that basically say whenever we have something like +02:00, GMT+2 and UTC+2, they all mean to say the same thing.

+2 means SUBTRACT 2 hours from the given time. -2 means ADD 2 hours to the given time.

For example,

2015-06-20T07:50+02:00 means 2015-06-20 5:50 in GMT. See that we SUBTRACT 2 hours FROM the given time?

2015-06-20T07:50 GMT-04:00 means 2015-06-20 11:50 in GMT. See that we ADD 4 hours TO the given time?

However, in Exam Essentials on Page 274 of Ch. 5, the authors said and I quote

Whether the format is -05:00, GMT-5, or UTC-5, you calculate by subtracting the offset from the time,....



This one line just contradicted everything the authors said earlier in Ch. 5.

Which one do I regard that to be true?

Either I'm missing some kind of understanding here or there must be something going on that led me to this contradiction AND confusion.

I've adapted the following code snippet from Enthuware. It's a working piece of code and I've tested it. Based on the code, GMT+2 means ADDING 2 hours to the given time. In other words, + means ADD and - means SUBTRACT, according to the following piece of code.



Thanks for your time.

Schmichael
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Schmichael Chen wrote:+2 means SUBTRACT 2 hours from the given time. -2 means ADD 2 hours to the given time.
2015-06-20T07:50+02:00 means 2015-06-20 5:50 in GMT. See that we SUBTRACT 2 hours FROM the given time?
2015-06-20T07:50 GMT-04:00 means 2015-06-20 11:50 in GMT. See that we ADD 4 hours TO the given time?
...
However, in Exam Essentials on Page 274 of Ch. 5, the authors said and I quote

Whether the format is -05:00, GMT-5, or UTC-5, you calculate by subtracting the offset from the time,....


OK, so what is
 -(-2)
and what is
 -(+2)
?

The fact is that both statements are correct. It just depends on what you regard as the "offset" value.

PS: Be careful how much bold you use in your posts; too much can come across as "shouting".

Winston
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Schmichael Chen wrote:+2 means SUBTRACT 2 hours from the given time. -2 means ADD 2 hours to the given time.
2015-06-20T07:50+02:00 means 2015-06-20 5:50 in GMT. See that we SUBTRACT 2 hours FROM the given time?
2015-06-20T07:50 GMT-04:00 means 2015-06-20 11:50 in GMT. See that we ADD 4 hours TO the given time?
...
However, in Exam Essentials on Page 274 of Ch. 5, the authors said and I quote

Whether the format is -05:00, GMT-5, or UTC-5, you calculate by subtracting the offset from the time,....


OK, so what is
 -(-2)
and what is
 -(+2)
?

The fact is that both statements are correct. It just depends on what you regard as the "offset" value.

PS: Be careful how much bold you use in your posts; too much can come across as "shouting".

Winston



Thanks, Winston. I did not mean to yell and I don't tend to yell in person. LOL! As I typed so much, I just wanted to draw the reader's attention to what I think they should pay attention to. That's all.

Schmichael
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Schmichael Chen wrote: I just wanted to draw the reader's attention to what I think they should pay attention to. That's all.


As you have seen, overuse does the exact opposite. Use bold and other text renditions sparingly, if it all.
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Schmichael Chen wrote:+2 means SUBTRACT 2 hours from the given time. -2 means ADD 2 hours to the given time.
2015-06-20T07:50+02:00 means 2015-06-20 5:50 in GMT. See that we SUBTRACT 2 hours FROM the given time?
2015-06-20T07:50 GMT-04:00 means 2015-06-20 11:50 in GMT. See that we ADD 4 hours TO the given time?
...
However, in Exam Essentials on Page 274 of Ch. 5, the authors said and I quote

Whether the format is -05:00, GMT-5, or UTC-5, you calculate by subtracting the offset from the time,....


OK, so what is
 -(-2)
and what is
 -(+2)
?

The fact is that both statements are correct. It just depends on what you regard as the "offset" value.

PS: Be careful how much bold you use in your posts; too much can come across as "shouting".

Winston



Winston,

Thanks but I believe your explanation addressed just the following two statements in the quote.

2015-06-20T07:50+02:00 means 2015-06-20 5:50 in GMT. See that we SUBTRACT 2 hours FROM the given time?

2015-06-20T07:50 GMT-04:00 means 2015-06-20 11:50 in GMT. See that we ADD 4 hours TO the given time?



I sincerely felt it did not address the contradiction presented in the book by the authors, i.e.

Whether the format is -05:00, GMT-5, or UTC-5, you calculate by subtracting the offset from the time,....



and here is why.

===========================================

+2 = - (-2)

means SUBTRACT 2 hours from the given time.

===========================================

-2 = - (+2)

means ADD 2 hours to the given time.

===========================================


Whether the format is -05:00, GMT-5, or UTC-5, you calculate by SUBTRACTING the offset from the time,....



-5 = - (+5)

Shouldn't we be adding 5 hours instead?

Why were the authors saying subtracting the offset in that quote above?

What is it that I'm missing here?

===========================================

There was GMT+2 in the code snippet I provided in my original post.

+ 2 = - (-2)

Shouldn't we also be subtracting 2 hours from the given value?

But the correct answer (I've confirmed the answer by running the provided code snippet) was ADDING 2 hours, not SUBTRACTING 2 hours.

What is it that I'm missing here?


Thanks.

Schmichael

PS
Don't mean to scream!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Schmichael,
It's just "colloquial" English in the summary. The subtracting by adding negative numbers thing. I'll make a note in our private list it can be clearer for next time. You understand it well from the way you are asking this.
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Schmichael,
It's just "colloquial" English in the summary. The subtracting by adding negative numbers thing. I'll make a note in our private list it can be clearer for next time. You understand it well from the way you are asking this.



Jeanne,

Thank you very much indeed. Thank you. I'm so happy to get an answer straight from one of the authors of the book. Ha....Ha....Ha....

Apart from that, I was just pretending to understand it all. In other words, I am just notorious for asking the right questions if I could quote a classmate I met in San Francisco. You are overly crediting me when you said "You understand it well from the way you are asking this."

I am afraid that I do not think I really get this down.

In fact, this has made me confused as much as Gaddafi did to me in the past.

Do you mind kindly clarifying this for me with some examples so that I get this stuff once and for all? Please?

In your explanation, it would be great if you also could comment on ZoneId.of("GMT+2") in the code snippet from Enthuware that I provided in my original question. I am more interested in GMT+2 part of it quite frankly.

Many thanks, Jeanne.

Have a good night to you.

Schmichael
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find it helpful to open a time zone map while reading this post. It is currently 3pm in New York (East Coast time at GMT - 4). Remember that Europe is "ahead" of us. Making GMT at 7pm and GMT+2 at 9pm.

With the GMT, example, ready time is:
2015-06-25T17:13:30Z

and GMT+2 is:
2015-06-25T19:13:30

Whereas if you were told that it is 19:13 in GMT+2, you'd subtract the 2 in order to find the time in GMT getting 17:13.
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:You might find it helpful to open a time zone map while reading this post. It is currently 3pm in New York (East Coast time at GMT - 4). Remember that Europe is "ahead" of us. Making GMT at 7pm and GMT+2 at 9pm.

With the GMT, example, ready time is:
2015-06-25T17:13:30Z

and GMT+2 is:
2015-06-25T19:13:30

Whereas if you were told that it is 19:13 in GMT+2, you'd subtract the 2 in order to find the time in GMT getting 17:13.



Jeanne, many thanks. Given a starting point or an end point with the time difference, it's easy for me to figure out the rest. What you said above made sense to me at once. My trouble was in figuring out the meaning or how to make sense when faced with a whole bunch of given sprawling numbers. Let me try one more time to see if I really get this. The following numbers are pulled from Ch 5 of your book.

2015-05-25T09:13:07.769 - 04:00 <==== The interpretation: The given time (and date to be precise) {2015-05-25T09:13:07.769} is 4 hours behind GMT.

2015-06-20T07:50 + 02:00 <==== The interpretation: The given time (and date to be precise) {2015-06-20T07:50} is 2 hours ahead of GMT.

2015-06-20T06:50 + 05:30 <==== The interpretation: The given time (and date to be precise) {2015-06-20T06:50} is 5 and 1/2 hours ahead of GMT.

2015-06-20T07:50 GMT- 04:00 <==== The interpretation: The given time (and date to be precise) {2015-06-20T07:50} is 4 hours behind GMT.

2015-06-20T04:50 GMT-07:00 <==== The interpretation: The given time (and date to be precise) {2015-06-20T04:50} is 7 hours behind GMT.

2015-06-20T07:50 - 07:00 <==== The interpretation: The given time (and date to be precise) {2015-06-20T07:50} is 7 hours behind GMT.

2015-06-20T07:50 + 05:30 <==== The interpretation: The given time (and date to be precise) {2015-06-20T07:50} is 5 and 1/2 hours ahead of GMT.

Jeanne, I'd be very much obliged if you could kindly confirm if all my interpretations are correct. If they are, I believe I finally get the concept.

In the given program in one of my earlier posts,

Instant start = Instant.parse("2015-06-25T16:13:30.00z"); <==== The interpretation: The variable start contains {2015-06-25T16:13:30.00z} and it's 0 hours away from GMT, i.e. it's indeed in GMT simply due to the offset value being 0.

Instant readyTime = start.plus(timeToCook); <=== The interpretation: The variable readyTime contains {2015-06-25T17:13:30.00z} as 1 hour is added to the start time to get this value in the variable readyTime. This too is in GMT because of the offset value being 0.

For the statement

LocalDateTime ltd = LocalDateTime.ofInstant(readyTime, ZoneId.of("GMT+2"));

,

we have 3 things here: readyTime, GMT and the variable ltd. Of course, we don't add 2 hours to any given moment in time in GMT to still want to remain in GMT. That would be ridiculous. We don't add 2 hours to a time in GMT to generate a value held inside the variable readyTime because that variable already contains a time that's already in GMT, i.e. 2015-06-25T17:13:30.00z + 00:00 or 2015-06-25T17:13:30.00z GMT+0.

That can only mean that we add 2 hours to 2015-06-25T17:13:30.00z in GMT to generate a time value that is 2 hours ahead of GMT. That new time value belongs in the variable ltd.

Is my understanding correct here?

Many thanks again and have a good weekend to you, Jeanne.

Schmichael
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yay. You understand it! Have a cow for spelling it out. Not only does this help you, but it helps other confused readers.
 
Schmichael Chen
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Yay. You understand it! Have a cow for spelling it out. Not only does this help you, but it helps other confused readers.



Brilliant! I'm delighted to hear that. Thank you very much indeed, Jeanne, for helping out this one confused user. Thank you.

Schmichael
 
I am going to test your electrical conductivity with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic