python time.time to datetime code example

Example 1: timestamp change python

import time
timestamp = 1547281745
datetime = time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timestamp))
print(datetime)

Example 2: timestamp to date python

from datetime import datetime

timestamp = 1586507536367
dt_object = datetime.fromtimestamp(timestamp)

Example 3: strptime python

import datetime
d =datetime.datetime.strptime("01/27/2012","%m/%d/%Y").strftime('%m/%d/%Y')
print d
01/27/2012

Example 4: python datetime to string iso format

from datetime import datetime
some_date = datetime.now()
iso_date_string = some_date.isoformat()

# For older version of python 
iso_date_string = some_date.strftime('%Y-%m-%dT%H:%M:%S.%f%z')