Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    If you've defined Local per the datetime docs, this also works: str(datetime.datetime.now(tz=Local)) Commented Apr 1, 2012 at 7:15
  • Be aware that this will print any use with the UTC offset that is currently in effect, which may not be the same that was or will be in effect at the time given by the datetime instance (due to DST). Commented Sep 15, 2013 at 11:56
  • LocalTimezone might fail for past dates if underlying time implementation doesn't use a historical timezone database (Windows is notably in this category). Commented Dec 3, 2013 at 13:40
  • 1
    I think the argument to astimezone should be empty: t.astimezone() Commented Jul 12, 2018 at 5:02