dtpy Flashcards
naive datetimes do not know
what timezone they are in
aware datetimes know
what timezone you are in
to create a naive date, type
datetime.date(2000, 12, 30)
you should not use a local time zone in apps for anything except
converting it to display for users.
datetime.datetime.now(), datetime.time.now(), datetime.date.now() return the time/date in
my local timezone from computer, but in a naive form.
to return the day of week in 0-6 format, type
my_datetime.weekday()
a timedelta represents
the amount of time between 2 dates or times
to create a timedelta of 7 days type
datetime.timedelta(days=7)
to print out what the date will be in 7 days, type
datetime.date().today() + datetime.timedelta(days=7)
if you subtract a date or time from a date or time you get a
timedelta
note: cannot add
to return the number of seconds of a timedelta, type
my_time_delta.total_seconds()
the parameters to datetime.time() are
hours, minutes, seconds, milliseconds.
to get the current datetime in utc
datetime. datetime.now(tz= pytz.UTC)
note: Yes, this gets the time local to there, not my local timeand then just setting UTC as timezone.
to make an aware datetime, type
datetime.datetime(2016,10,20, 20, 10, 20000, tzinfo = pytz.UTC)
to convert a timezone aware datetime to the concurrent local time in a different timezone, type
Like at this time here, whats the local time there?
my_datetime.astimezone(pytz.timezone(‘TIMEZONE/STRING’))