{"id":802,"date":"2012-08-04T23:29:24","date_gmt":"2012-08-04T23:29:24","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=802"},"modified":"2026-06-28T17:38:19","modified_gmt":"2026-06-29T00:38:19","slug":"python-datetime-datetime-now-that-is-timezone-aware","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=802","title":{"rendered":"Python datetime.datetime.now() that is timezone aware"},"content":{"rendered":"I recently needed to print out the time with timeszone name but when I used the %Z paramter it was blank. I fixed it by using the dateutil package as shown in the short example below.\n<!--more-->\n\n<pre class=\"wp-block-code language-python\"><code class=\"language-python\">#!\/usr\/bin\/env python\nimport datetime\nfrom dateutil.tz import tzlocal\n\n# Get the current date\/time with the timezone.\nnow = datetime.datetime.now(tzlocal())\nfmt1 = now.strftime('%Y-%m-%d %H:%M:%S %Z')\nfmt2 = now.strftime('%A, %B %d, %Y %Z')\n\n# Print it out.\nprint 'fmt1 = %s' % (fmt1)\nprint 'fmt2 = %s' % (fmt2)<\/code><\/pre>\n\n\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to print out the time with timeszone name but when I used the %Z paramter it was blank. I fixed it by using the dateutil package as shown in the short example below.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=802"}],"version-history":[{"count":4,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/802\/revisions"}],"predecessor-version":[{"id":1786,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/802\/revisions\/1786"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}