2009-12-23

 

Python: Convert datetime to unix seconds

A quick solution:
$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> tt = datetime.datetime( 2009, 12, 23, 6, 0, 0 )
>>> print int( tt.strftime('%s') )
1261540800
>>>
$ date --date="2009-12-23 06:00:00" +%s
1261540800


For a practical implementation, see http://sites.google.com/site/pythonbits/Home/date-and-time-comparison

Labels:


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?