Recap : library : datetime, pytz
# Introduction to Timezones
# Actually, Use putz instead
# Timezonapalooza
---
: So when we create a date time or time object, we can specify the time zone.
: And now, that object knows where it is in the world and how to sort itself out amongst all of our other objects.
: We say that a date time object that knows its time zone, is aware, and those that don't are naive.
import datetime
pacific = datetime.timezone(datetime.timedelta(hours=-8))
eastern = datetime.timezone(datetime.timedelta(hours=-5))
naive = datetime.datetime(2014, 4, 21, 9)
aware = datetime.datetime(2014, 4, 21, 9, tzinfo=pacific)
# now, let's change the timezone.. ( what's that mean? a ha ! travel to the another world synchronously )
# Tool : astimezone
# Q : as + timezone/.. "as" ?
aware.astimezone(eastern)
# later pytz library ( hours=-8, hours=-5 is headache. )
naive is a datetime with no timezone.
Create a new timezone for US/Pacific, which is 8 hours behind UTC (UTC-08:00).
Then make a new variable named hill_valley that is naive with its tzinfo attributereplaced with the US/Pacific timezone you made.
import datetime
naive = datetime.datetime(2015, 10, 21, 4, 29)
us_pacific = datetime.timezone(datetime.timedelta(hours=-8))
hill_valley = naive.replace(tzinfo=us_pacific)
Great, but replace just sets the timezone, it doesn't move the datetime to the new timezone. Let's move one.
Make a new timezone that is UTC+01:00.
Create a new variable named paris that uses your new timezone and the astimezonemethod to change hill_valley to the new timezone.
" Think very important. ..
댓글 없음:
댓글 쓰기