{"id":1517,"date":"2018-08-26T19:53:53","date_gmt":"2018-08-26T11:53:53","guid":{"rendered":"http:\/\/www.yinyubo.cn\/?p=141"},"modified":"2018-08-26T19:53:53","modified_gmt":"2018-08-26T11:53:53","slug":"yyyy-mm-ddthhmmss-2","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1517","title":{"rendered":"\u5c06Jira\u83b7\u53d6\u7684UTC\u65f6\u95f4\u8f6c\u672c\u5730\u65f6\u95f4yyyy-MM-dd&#8217;T&#8217;HH:mm:ss"},"content":{"rendered":"<p>\u901a\u8fc7API\u83b7\u5f97jira \u5907\u6ce8(comment)\u7684\u66f4\u65b0\u65f6\u95f4\uff0c\u53d1\u73b0\u83b7\u5f97\u7684UTC\u65f6\u95f4\u683c\u5f0f\u4e3a<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">2018-08-14T02:52:22.216+0000<\/code><br \/>\n\u8fd9\u4e2a\u65f6\u5019\uff0c\u5982\u679c\u9700\u8981\u8f6c\u6362\u6210<code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">datetime \uff1ayyyy-MM-dd'T'HH:mm:ss<\/code>\u683c\u5f0f\uff0c<br \/>\n\u6216\u8005<code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">date:yyyy-MM-dd<\/code>,\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801:<\/p>\n<pre class=\"lang:python decode:true\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">#!\/usr\/bin\/python\n# -*- coding:utf-8 -*-\nimport re\nimport time\nfrom datetime import datetime\ndef utc2local(utc_st):\n    # UTC\u65f6\u95f4\u8f6c\u672c\u5730\u65f6\u95f4\uff08+8:00\uff09\n    now_stamp = time.time()\n    local_time = datetime.fromtimestamp(now_stamp)\n    utc_time = datetime.utcfromtimestamp(now_stamp)\n    offset = local_time - utc_time\n    local_st = utc_st + offset\n    return local_st\ndef local2utc(local_st):\n    # \u672c\u5730\u65f6\u95f4\u8f6cUTC\u65f6\u95f4\uff08-8:00\uff09\n    time_struct = time.mktime(local_st.timetuple())\n    utc_st = datetime.utcfromtimestamp(time_struct)\n    return utc_st\ndef utc_format(utcstr):\n    \"\"\"\n    \u5c06\u4e0d\u6807\u51c6\u7684utc\u65f6\u95f4\u5b57\u7b26\u4e32\u8f6c\u6362\u6210datetime\u683c\u5f0f\n    :param utcstr: \u4e0d\u6807\u51c6\u7684utc\u5b57\u7b26\u4e32\uff0c\u5982\u20182018-04-23T03:43:35.000+0000\u2019\n    :return:\n    \"\"\"\n    utcstr = re.sub('.ddd+0000', '', utcstr, count=1)\n    try:\n        UTC_FORMAT = \"%Y-%m-%dT%H:%M:%S\"\n        d_time = datetime.strptime(utcstr, UTC_FORMAT)\n    except Exception:\n        UTC_FORMAT = \"%Y-%m-%d %H:%M:%S\"\n        d_time = datetime.strptime(utcstr, UTC_FORMAT)\n    return d_time\ndef get_local_date(utcstr):\n    \"\"\"\n    \u5c06jira\u8fd4\u56de\u7684str\u7c7b\u578b\u7684\u65f6\u95f4\uff0c\u8f6c\u6362\u6210datetime\u683c\u5f0f,\u5e76\u53bb\u9664\u65e5\u671f\u4e4b\u540e\u7684\u5185\u5bb9\uff08\u63d0\u4f9b\u7ed9SprintDailyIssuesBar\u4f7f\u7528\u7684\u65e5\u671f\u5904\u7406\u63a5\u53e3\uff09\n    :param utcstr: jira\u8fd4\u56de\u7684time\u5b57\u7b26\u4e32\n    :return:datetime\u683c\u5f0f\n    \"\"\"\n    utc_st = utc_format(utcstr)\n    # print utc_st\n    local_st = utc2local(utc_st)\n    # print local_st\n    local_str = local_st.strftime('%Y-%m-%d')\n    local_date = datetime.strptime(local_str, \"%Y-%m-%d\")\n    # print local_date\n    return local_date\ndef get_local_datetime_str(utcstr):\n    \"\"\"\n    \u5c06jira\u8fd4\u56de\u7684str\u7c7b\u578b\u7684UTC\u65f6\u95f4\uff0c\u8f6c\u6362\u6210str\u7c7b\u578b\u7684local time,\u5305\u542b\u5177\u4f53\u7684\u65f6\u3001\u5206\u3001\u79d2\uff08\u63d0\u4f9b\u7ed9tableData\u4f7f\u7528\uff0c\u8f6c\u6362\u65f6\u95f4\uff09\n    :param utcstr: jira\u8fd4\u56de\u7684time\u5b57\u7b26\u4e32\n    :return:string\n    \"\"\"\n    utc_st = utc_format(utcstr)\n    # print utc_st\n    local_st = utc2local(utc_st)\n    # print local_st\n    local_str = local_st.strftime('%Y-%m-%d %H:%M:%S')\n    return local_str\n if __name__ == '__main__':\n     utcstr1 = '2018-08-14T02:52:22.216+0000'\n     tt=get_local_datetime_str(utcstr1)\n     print(tt)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7API\u83b7\u5f97jira \u5907\u6ce8(comment)\u7684\u66f4\u65b0\u65f6\u95f4\uff0c\u53d1\u73b0\u83b7\u5f97\u7684UTC\u65f6\u95f4\u683c\u5f0f\u4e3a 2018-08-14T0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1517","post","type-post","status-publish","format-standard","hentry","category-jira"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1517"}],"version-history":[{"count":0,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1517\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}