Python and datetime

Links

Here are some links

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close