python epoch to datetime

Do you want to know the information regarding “python epoch to datetime”. If yes, you’re in the correct article.

python epoch to datetime

>>> import datetime
>>> datetime.datetime.fromtimestamp(1347517370).strftime('%Y-%m-%d %H:%M:%S')
'2012-09-13 14:22:50' # Local time
datetime_time = datetime.datetime.fromtimestamp(epoch_time)
>>> import datetime
>>> datetime.datetime.utcfromtimestamp(1347517370).strftime('%Y-%m-%d %H:%M:%S')
  '2012-09-13 06:22:50'
# utc time
>>> datetime.datetime(2012,4,1,0,0).timestamp()
1333234800.0
>>> datetime.datetime.utcfromtimestamp(1347517370).strftime('%Y-%m-%d %H:%M:%S')
  '2012-09-13 06:22:50'
>>> datetime.datetime.fromtimestamp(1284286794)
datetime.datetime(2010, 9, 12, 11, 19, 54)

Final Words

I hope this post helps you to know about “python epoch to datetime”. If you have any doubts regarding this article please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment