Convert Python UTC Datetime Object To UNIX Timestamp
Convert Python UTC Datetime Object To UNIX Timestamp
Ruslan's Blog
The harder you work the luckier you get
HOME
ABOUT
To search, type and hit enter
Looks fine, but I cant for the life of me understand why the function timegm is part of the calendar
module.
From Python official documentation:
calendar.timegm(tuple)
An unrelated but handy function that takes a time tuple such as returned by the gmtime()
function in the time module, and returns the corresponding Unix timestamp value, assuming an
epoch of 1970, and the POSIX encoding. In fact, time.gmtime() and timegm() are each others
inverse.
If you enjoyed this post why not subscribe via email or my RSS feed and get the latest updates
immediately. You can also follow me on GitHub or Twitter.
{ 13 comments read them below or add one }
1/6
10/27/2014
2/6
10/27/2014
>>> time.mktime(d.timetuple())
1311236002.0
[/sourcecode]
Reply
3/6
10/27/2014
Thank God for this post, I had wasted half a day looking for an easy way to get the UTC
timestamp before running into this.
Reply
4/6
10/27/2014
Website
Submit
Follow Me
Categories
python (72)
emacs (28)
bash (18)
erlang (14)
pyramid (3)
uncategorized (2)
Recent Posts
How to Pretty Print XML with lxml
Need for Speed SENDFILE System Call
http://ruslanspivak.com/2011/07/20/how-to-convert-python-utc-datetime-object-to-unix-timestamp/
5/6
10/27/2014
Self-Pipe Trick
SIGPIPE 101
Simple Examples of Concurrent Server Design in Python
Recent Comments
Igor Kupczynski on How to Pretty Print XML with lxml
AnneTheAgile on BASH history incremental search forward
cesium62 on How to convert Python UTC datetime object to UNIX timestamp
Aleksei on Urlencode and urldecode from a command line
vasya on Urlencode and urldecode from a command line
Archives
May 2014
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
June 2010
April 2010
February 2010
December 2009
November 2009
October 2009
April 2009
March 2009
April 2008
November 2007
October 2007
September 2007
August 2007
Copyright 2012 - Ruslan Spivak
http://ruslanspivak.com/2011/07/20/how-to-convert-python-utc-datetime-object-to-unix-timestamp/
6/6