python datetime to timestamp

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

python datetime to timestamp

import datetime

today = datetime.datetime.now()
date_time = today.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)
from datetime import datetime

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

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))
import datetime
now = datetime.datetime.today()
timestamp = datetime.datetime.timestamp(now)
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1322697600.0

Final Words

I hope this post helps you to know about “python datetime to timestamp”. If you have any questions regarding this post please let us know via the comment section. Share this article with your friends & 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