Linked Questions
114 questions linked to/from Converting datetime.date to UTC timestamp in Python
28 votes
2 answers
142k views
python datetime to float with millisecond precision [duplicate]
What is a classy way to store date and time information in a float in python with millisecond precision? Edit: I'm using python 2.7 I've hacked together the following: DT = datetime.datetime(2016,01,...
0 votes
0 answers
101 views
Why am I gaining an hour when converting to/from epoch timestamp? [duplicate]
example = datetime.datetime(2014, 8, 19, 14, 18, 49, 435413, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=-240, name=None)) datetime.datetime.fromtimestamp(time.mktime(example.timetuple())) datetime....
834 votes
19 answers
1.4m views
How do I get the current time in milliseconds in Python?
How do I get the current time in milliseconds in Python?
443 votes
26 answers
874k views
How to convert local time string to UTC?
How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. ...
692 votes
10 answers
1.3m views
Does Python's time.time() return the local or UTC timestamp?
Does time.time() in the Python time module return the system's time or the time in UTC?
496 votes
13 answers
617k views
How can I convert a datetime object to milliseconds since epoch (unix time) in Python?
I have a Python datetime object that I want to convert to unix time, or seconds/milliseconds since the 1970 epoch. How do I do this?
347 votes
17 answers
867k views
Convert string date to timestamp in Python
How to convert a string in the format "%d/%m/%Y" to timestamp? "01/12/2011" -> 1322697600
370 votes
10 answers
608k views
What is the easiest way to get current GMT time in Unix timestamp format?
Python provides different packages (datetime, time, calendar) as can be seen here in order to deal with time. I made a big mistake by using the following to get current GMT time time.mktime(datetime....
350 votes
14 answers
533k views
How to convert a UTC datetime to a local datetime using only standard library?
I have a python datetime instance that was created using datetime.utcnow() and persisted in database. For display, I would like to convert the datetime instance retrieved from the database to local ...
321 votes
13 answers
691k views
In Python, how do you convert a `datetime` object to seconds?
I have a bunch of datetime objects and I want to calculate the number of seconds since a fixed time in the past for each one (for example since January 1, 1970). import datetime t = datetime.datetime(...
306 votes
12 answers
280k views
Python Create unix timestamp five minutes in the future
I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX style ...
320 votes
12 answers
726k views
Convert datetime to Unix timestamp and convert it back in python
I have dt = datetime(2013,9,1,11), and I would like to get a Unix timestamp of this datetime object. When I do (dt - datetime(1970,1,1)).total_seconds() I got the timestamp 1378033200. When ...
315 votes
8 answers
559k views
Convert python datetime to epoch with strftime
I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime....
111 votes
11 answers
255k views
get UTC timestamp in python with datetime
Is there a way to get the UTC timestamp by specifying the date? What I would expect: datetime(2008, 1, 1, 0, 0, 0, 0) should result in 1199145600 Creating a naive datetime object means that there ...
77 votes
10 answers
74k views
Getting computer's UTC offset in Python
In Python, how do you find what UTC time offset the computer is set to?