{"id":1361,"date":"2009-01-03T20:57:38","date_gmt":"2009-01-03T20:57:38","guid":{"rendered":"http:\/\/wiki.davelevy.info\/?p=1361"},"modified":"2022-12-01T21:43:37","modified_gmt":"2022-12-01T21:43:37","slug":"python-and-datetime","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/python-and-datetime\/","title":{"rendered":"Python and datetime"},"content":{"rendered":"<p>Some notes on python and its datetime routines.<br \/>\n<!--more--><\/p>\n<h3>Links<\/h3>\n<p>Here are some links<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/datetime.html\">http:\/\/docs.python.org\/library\/datetime.html,<\/a> Official Documentation<\/li>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/time.html\">http:\/\/docs.python.org\/library\/time.html,<\/a> Official Documentation<\/li>\n<li><a href=\"http:\/\/pylab.blogspot.com\/2007\/09\/python-datetime-guide.html\">http:\/\/pylab.blogspot.com\/2007\/09\/python-datetime-guide.html<\/a> , this is pretty good with lots of examples<\/li>\n<li><del title=\"now gone away\">http:\/\/www.aczoom.com\/cms\/blog\/ac\/2007-02-24\/strftime-in-python<\/del> not surprisingly concentrates on <i>strftime<\/i> which can be used to create formatted date\/time strings,\u00a0\u00a0<a href=\"http:\/\/strftime.org\/\">http:\/\/strftime.org\/<\/a> is an alternate source of documentation for <em>strftime<\/em><\/li>\n<li><a href=\"http:\/\/docs.python.org\/library\/time.html#time.strftime,\">http:\/\/docs.python.org\/library\/time.html#time.strftime,<\/a> Official documents, listing the strftime parameters<\/li>\n<\/ul>\n<h3>Examples<\/h3>\n<p>An example of using datetime is<\/p>\n<div>\n<pre>import time\r\nimport datetime\r\nnow=datetime.datetime.now() \r\n\r\n#now.tzinfo = 'GMT'; # fails, now.tzinfo is immutable\r\n\r\nprint now.ctime() print now.isoformat() print now.tzinfo<\/pre>\n<\/div>\n<p>but otherwise produces the following output<\/p>\n<div>\n<pre>Fri Jan  2 15:15:07 2009\r\n2009-01-02T15:15:07.896000\r\nNone<\/pre>\n<\/div>\n<p>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 <i>datetime<\/i> doesn&#8217;t do TimeZones.<\/p>\n<p>Obviously, using the from statement would change the call syntax<\/p>\n<div>\n<pre>from datetime import datetime\r\nnow=datetime.now()<\/pre>\n<\/div>\n<p>should work<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some notes on python and its datetime routines.<\/p>\n","protected":false},"author":1,"featured_media":3767,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[27,3],"tags":[458,36,45,457,911],"class_list":["post-1361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","category-technology","tag-datetime","tag-programming","tag-python","tag-siftware","tag-technology"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2011\/10\/python-w631.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=1361"}],"version-history":[{"count":8,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1361\/revisions"}],"predecessor-version":[{"id":3497,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/1361\/revisions\/3497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/3767"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=1361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=1361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=1361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}