I have a date that looks like this :
November 19th 2015, 12:48:34.402
And I need to figure out a way to convert it to a timestamp. I'm trying it this way but I can't find the right pattern to format it.
time.mktime(datetime.datetime.strptime(parsed["_timestamp"], "%B %d %Y, %H:%M:%S").timetuple())
Any suggestion on maybe how to get the right format?
Your formatting string was a bit off. You need to include the th, rd, etc., the decimal point for the seconds, and the microseconds (which is %f). We'll find the proper th/etc. with a split():
>>> a = 'November 19th 2015, 12:48:34.402'
>>> time.mktime(datetime.datetime.strptime(a, "%B %d{} %Y, %H:%M:%S.%f".format(a.split()[1][-2:])).timetuple())
1447966114.0
>>> a = 'November 23rd 2015, 12:48:34.402'
>>> time.mktime(datetime.datetime.strptime(a, "%B %d{} %Y, %H:%M:%S.%f".format(a.split()[1][-2:])).timetuple())
1448311714.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With