{"id":7040,"date":"2015-01-01T14:47:19","date_gmt":"2015-01-01T06:47:19","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7040"},"modified":"2015-01-01T14:47:19","modified_gmt":"2015-01-01T06:47:19","slug":"python-iso8601-to-localtime","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7040","title":{"rendered":"python iso8601\u8f6c\u4e3a\u672c\u5730\u65f6\u95f4"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>\r\n#!\/usr\/bin\/env python\r\n#-*- coding:utf-8 -*-\r\n#author: jpuyy.com date\r\n#modified by xx at date\r\n#import time\r\n#from dateutil import tz\r\n\r\nfrom datetime import datetime, timedelta, tzinfo\r\n\r\nclass GMT8(tzinfo):\r\n    delta = timedelta(hours=8)\r\n    def utcoffset(self, dt):\r\n        return self.delta\r\n    def tzname(self, dt):\r\n        return \"GMT+8\"\r\n    def dst(self, dt):\r\n        return self.delta\r\n\r\nclass GMT(tzinfo):\r\n    delta = timedelta(0)\r\n    def utcoffset(self, dt):\r\n        return self.delta\r\n    def tzname(self, dt):\r\n        return \"GMT+0\"\r\n    def dst(self, dt):\r\n        return self.delta\r\n\r\na = \"2014-12-13T10:42:28.000Z\"\r\nfrom_tzinfo = GMT()\r\nlocal_tzinfo = GMT8()\r\n\r\ngmt_time = datetime.strptime(a, '%Y-%m-%dT%H:%M:%S.%fZ')\r\ngmt_time = gmt_time.replace(tzinfo=from_tzinfo)\r\nlocal_time = gmt_time.astimezone(local_tzinfo)\r\n\r\nprint gmt_time\r\nprint local_time\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; #!\/usr\/bin\/env python #-*- coding:utf-8 -*- #author: jpuyy.com date #modified by xx at date #import time #from dateutil import tz from datetime import datetime, timedelta, tzinfo class GMT8(tzinfo): delta = timedelta(hours=8) def utcoffset(self, dt): return self.delta def tzname(self, dt): return &#8220;GMT+8&#8221; def dst(self, dt): return self.delta class GMT(tzinfo): delta = timedelta(0) def utcoffset(self, dt): [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-7040","post","type-post","status-publish","format-standard","hentry","category-life"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7040"}],"version-history":[{"count":1,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7040\/revisions"}],"predecessor-version":[{"id":7041,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7040\/revisions\/7041"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}