Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string date to timestamp in Python

How to convert a string in the format "%d/%m/%Y" to timestamp?

"01/12/2011" -> 1322697600 
like image 407
Shankar Cabus Avatar asked Mar 09 '12 16:03

Shankar Cabus


People also ask

Can we convert string to timestamp?

To convert a date string to a timestamp: Pass the date string to the Date() constructor. Call the getTime() method on the Date object. The getTime method returns the number of milliseconds since the Unix Epoch.


1 Answers

>>> import time >>> import datetime >>> s = "01/12/2011" >>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple()) 1322697600.0 
like image 179
Katriel Avatar answered Oct 16 '22 11:10

Katriel