epoch to datetime python

47

epoch to datetime python -

>>> import datetime
>>> datetime.datetime.fromtimestamp(1347517370).strftime('%Y-%m-%d %H:%M:%S')
'2012-09-13 14:22:50' # Local time

convert epoch to date time in python -

datetime_time = datetime.datetime.fromtimestamp(epoch_time)

epoch to datetime utc python -

>>> import datetime
>>> datetime.datetime.utcfromtimestamp(1347517370).strftime('%Y-%m-%d %H:%M:%S')
  '2012-09-13 06:22:50'
# utc time

current date to epoch python -

>>> datetime.datetime(2012,4,1,0,0).timestamp()
1333234800.0

Comments

Submit
0 Comments