Python: how to create a date from a Unix timestamp

In Python we can create a date from a Unix timestamp.

We can use the fromtimestamp() method of the datetime module:

from datetime import datetime

def timestamp_to_date_format(ts_unix):
    dt_format = '%Y-%m-%d'
    return datetime.fromtimestamp(ts_unix).strftime(dt_format)
Back to top