I have a certain date on a variable in this d/m/Y
format. See:
strDate = "29/03/2017"
How to convert this date to timestamp in Python?
I have a certain date on a variable in this d/m/Y
format. See:
strDate = "29/03/2017"
How to convert this date to timestamp in Python?
>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1322697600.0
Would convert this data "01/12/2011" - > 1322697600
You can try this "simplified" form too:
>>> int(datetime.datetime.strptime('01/12/2011', '%d/%m/%Y').strftime("%s"))
The timestamp has several formats: ISO-8601, rfc-2822, rfc-3339, North American, European, Unix epoch, POSIX time, big-endian and even custom formats. [ reference1 ]
The most convenient is to convert the date string to date objects. Then format the presentation as you want.
There is a example in the .stackoverflow.com with three ways to solve this problem at execution here . The solutions feature the use of datetime, time, and arrow packages.