Some notes on python and its datetime routines.
Links
Here are some links
- http://docs.python.org/library/datetime.html, Official Documentation
- http://docs.python.org/library/time.html, Official Documentation
- http://pylab.blogspot.com/2007/09/python-datetime-guide.html , this is pretty good with lots of examples
http://www.aczoom.com/cms/blog/ac/2007-02-24/strftime-in-pythonnot surprisingly concentrates on strftime which can be used to create formatted date/time strings, http://strftime.org/ is an alternate source of documentation for strftime- http://docs.python.org/library/time.html#time.strftime, Official documents, listing the strftime parameters
Examples
An example of using datetime is
import time import datetime now=datetime.datetime.now() #now.tzinfo = 'GMT'; # fails, now.tzinfo is immutable print now.ctime() print now.isoformat() print now.tzinfo
but otherwise produces the following output
Fri Jan 2 15:15:07 2009 2009-01-02T15:15:07.896000 None
I performed these tests on a windows XP box. tzinfo is empty is this a windows/configuration thing? I can test this with UNIX. I tried setting the TZ variable before running the program and it makes no difference. I found one reference that says Python datetime doesn’t do TimeZones.
Obviously, using the from statement would change the call syntax
from datetime import datetime now=datetime.now()
should work