Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) Where on Earth do Timezones Make Sense? Introduction to Timezones

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

why am i getting 12 noon

in the video approx on 3 minutes kenneth prints out the aware.astimezone(eastern). the time shown is 12noon. i don understand how he gets 12 noon. my understanding is eastern timezone is set to -5 , so as the aware is set to 21 should we minus 5 from this.

clearly i am wrong but why?

thanks

4 Answers

21 is the day not the hour. The hour is 9. aware is in the pacific timezone at (hours=-8). Changing to the eastern timezone (hours=-5) is +3 so the time would be 9 + 3 = 12.

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

Thanks for your reply almost there i think! From my understanding we created two timezones a pacific timezone which is set to -8 offset the UTC time and a second timezone called eastern which is -5 off set from UTC

we created an aware variable allocating it to the pacific timezone.

then when we ran aware.astimezone(eastern) we are off setting this against the pacific timezone Am i correct up to this point

lastly on the assumption if the above is correct how is the + 3 as as both timezone are -8 and -5 respectively ? This is probably a maths question

Yes in this case astimezone returns the eastern local time for the pacific time in aware. The difference between new and old is (-5 - (-8)) or +3. So when it is 9 am in the pacific time zone it is 12 pm in the eastern time zone.

Sohail Mirza
seal-mask
.a{fill-rule:evenodd;}techdegree
Sohail Mirza
Python Web Development Techdegree Student 5,158 Points

ok understood ..but then confused again.. kenneth continue to give two more examples he create two more time zones one for auckland and one for mumbai. auckland is 13 hours ahead when he rans aware he gets the following day but more importantly he gets 6am and mumbai is 5.5 hours ahead but he rans aware he gets 22.30

I dont understand why ? Thanks

For auckland

13-(-8) = +21 so when it is 9 am in the pacific it is 21 hours ahead in Auckland. +15 hours gets you to 12 am on the following day. Add another 6 (for 21 total hours) is 6am.

For mumbai

5-(-8) = +13 hours

30 - 0 = + 30 minutes

+12 hours is 9pm. Add another hour (for 13 total hours) is 10 pm. Add 30 minutes is 10:30 pm or 22:30 (24 hour clock)