{"id":4005,"date":"2023-12-01T15:07:55","date_gmt":"2023-12-01T15:07:55","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=4005"},"modified":"2023-12-01T15:07:56","modified_gmt":"2023-12-01T15:07:56","slug":"python-date-time-reformatter","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=4005","title":{"rendered":"Python: Date Time Reformatter"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A simple function that takes a DateTime in the format: <strong>2023-11-29T06:41:20-08:00<\/strong> and outputs it in a much more pretty: <strong>29\/11\/2023 06:41:20 -0800<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see its switching to the DDMMYY date format, followed by the time and finally the timezone.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env python\nfrom datetime import datetime\n\ndef F_prettyDateTime(strlongdate):\r\n   date_format = '%Y-%m-%dT%H:%M:%S%z'\r\n   date_obj = datetime.strptime(strlongdate,date_format)\r\n   return date_obj.strftime('%d\/%m\/%Y %H:%M:%S %z')\n\nF_prettyDateTime(\"2023-11-29T06:41:20-08:00\")\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A simple function that takes a DateTime in the format: 2023-11-29T06:41:20-08:00 and outputs it in a much more pretty: 29\/11\/2023 06:41:20 -0800. As you can see its switching to the DDMMYY date format, followed by the time and finally the timezone.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,20],"tags":[],"class_list":["post-4005","post","type-post","status-publish","format-standard","hentry","category-python","category-random"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4005"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4005\/revisions"}],"predecessor-version":[{"id":4006,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4005\/revisions\/4006"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}