Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Datetime with Timezone

datetime.datetime(2018, 8, 4, 9, 42, 7, 168006, tzinfo=datetime.timezone.utc)

Localize a datetime Object

datetime.datetime(2018, 9, 12, 10, 36, 1, 891554)
datetime.datetime(2018, 9, 12, 10, 36, 1, 891554, tzinfo=<UTC>)

Convert a datetime Object to Another Timezone

Notice that you cannot call the method astimezone on a naive datetime (without timezone) before Python 3.6. You have to localize it with timezone first. Things become easier in Python 3.6.

<DstTzInfo 'America/Los_Angeles' LMT-1 day, 16:07:00 STD>
datetime.datetime(2018, 8, 4, 2, 21, 11, 155611, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>)

Timestamp to datetime with Timezone

Format a datetime Object with Timezone

'2018-09-12 03:42:46 PDT'

Get Current Timezone

('PST', 'PDT')