Search code examples
pythondatetimetimetimezoneepoch

Convert any epoch to human readable format for system timezone


This answer explains how to convert any given epoch to a non-localized datetime.

This answer explains how to convert the epoch for right now to a human readable format for a pre-defined timezone.

This answer explains how to get the current system timezone, but not with pyzt, which is used in the human readable format answer.

How do I convert any given epoch to a human readable format for the system timezone?


Solution

  • time.strftime combined with time.localtime should do the trick. The %Z option will output the system timezone. For example:

    >>> print time.strftime("%Z - %Y/%m/%d, %H:%M:%S", time.localtime(time.time()))
    CDT - 2014/07/15, 13:32:19
    

    Here, you can replace time.time() with your chosen epoch.