{"id":356,"date":"2022-01-17T09:54:37","date_gmt":"2022-01-17T01:54:37","guid":{"rendered":"http:\/\/47.98.165.52\/?p=356"},"modified":"2022-06-19T21:19:44","modified_gmt":"2022-06-19T13:19:44","slug":"python-%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0time-strftime%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"\/?p=356","title":{"rendered":"Python \u5e38\u7528\u51fd\u6570time.strftime()\u7b80\u4ecb"},"content":{"rendered":"<p>time.strftime()\u53ef\u4ee5\u7528\u6765\u83b7\u5f97\u5f53\u524d\u65f6\u95f4\uff0c\u53ef\u4ee5\u5c06\u65f6\u95f4\u683c\u5f0f\u5316\u4e3a\u5b57\u7b26\u4e32\u7b49\u7b49<br \/>\n\u683c\u5f0f\u547d\u4ee4\u5217\u5728\u4e0b\u9762\uff1a\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>%a \u661f\u671f\u51e0\u7684\u7b80\u5199<br \/>\n%A \u661f\u671f\u51e0\u7684\u5168\u79f0<br \/>\n%b \u6708\u5206\u7684\u7b80\u5199<br \/>\n%B \u6708\u4efd\u7684\u5168\u79f0<br \/>\n%c \u6807\u51c6\u7684\u65e5\u671f\u7684\u65f6\u95f4\u4e32<br \/>\n%C \u5e74\u4efd\u7684\u540e\u4e24\u4f4d\u6570\u5b57<br \/>\n%d \u5341\u8fdb\u5236\u8868\u793a\u7684\u6bcf\u6708\u7684\u7b2c\u51e0\u5929<br \/>\n%D \u6708\/\u5929\/\u5e74<br \/>\n%e \u5728\u4e24\u5b57\u7b26\u57df\u4e2d\uff0c\u5341\u8fdb\u5236\u8868\u793a\u7684\u6bcf\u6708\u7684\u7b2c\u51e0\u5929<br \/>\n%F \u5e74-\u6708-\u65e5<br \/>\n%g \u5e74\u4efd\u7684\u540e\u4e24\u4f4d\u6570\u5b57\uff0c\u4f7f\u7528\u57fa\u4e8e\u5468\u7684\u5e74<br \/>\n%G \u5e74\u5206\uff0c\u4f7f\u7528\u57fa\u4e8e\u5468\u7684\u5e74<br \/>\n%h \u7b80\u5199\u7684\u6708\u4efd\u540d<br \/>\n%H 24\u5c0f\u65f6\u5236\u7684\u5c0f\u65f6<br \/>\n%I 12\u5c0f\u65f6\u5236\u7684\u5c0f\u65f6<br \/>\n%j \u5341\u8fdb\u5236\u8868\u793a\u7684\u6bcf\u5e74\u7684\u7b2c\u51e0\u5929<br \/>\n%m \u5341\u8fdb\u5236\u8868\u793a\u7684\u6708\u4efd<br \/>\n%M \u5341\u65f6\u5236\u8868\u793a\u7684\u5206\u949f\u6570<br \/>\n%n \u65b0\u884c\u7b26<br \/>\n%p \u672c\u5730\u7684AM\u6216PM\u7684\u7b49\u4ef7\u663e\u793a<br \/>\n%r 12\u5c0f\u65f6\u7684\u65f6\u95f4<br \/>\n%R \u663e\u793a\u5c0f\u65f6\u548c\u5206\u949f\uff1ahh:mm<br \/>\n%S \u5341\u8fdb\u5236\u7684\u79d2\u6570<br \/>\n%t \u6c34\u5e73\u5236\u8868\u7b26<br \/>\n%T \u663e\u793a\u65f6\u5206\u79d2\uff1ahh:mm:ss<br \/>\n%u \u6bcf\u5468\u7684\u7b2c\u51e0\u5929\uff0c\u661f\u671f\u4e00\u4e3a\u7b2c\u4e00\u5929 \uff08\u503c\u4ece0\u52306\uff0c\u661f\u671f\u4e00\u4e3a0\uff09<br \/>\n%U \u7b2c\u5e74\u7684\u7b2c\u51e0\u5468\uff0c\u628a\u661f\u671f\u65e5\u505a\u4e3a\u7b2c\u4e00\u5929\uff08\u503c\u4ece0\u523053\uff09<br \/>\n%V \u6bcf\u5e74\u7684\u7b2c\u51e0\u5468\uff0c\u4f7f\u7528\u57fa\u4e8e\u5468\u7684\u5e74<br \/>\n%w \u5341\u8fdb\u5236\u8868\u793a\u7684\u661f\u671f\u51e0\uff08\u503c\u4ece0\u52306\uff0c\u661f\u671f\u5929\u4e3a0\uff09<br \/>\n%W \u6bcf\u5e74\u7684\u7b2c\u51e0\u5468\uff0c\u628a\u661f\u671f\u4e00\u505a\u4e3a\u7b2c\u4e00\u5929\uff08\u503c\u4ece0\u523053\uff09<br \/>\n%x \u6807\u51c6\u7684\u65e5\u671f\u4e32<br \/>\n%X \u6807\u51c6\u7684\u65f6\u95f4\u4e32<br \/>\n%y \u4e0d\u5e26\u4e16\u7eaa\u7684\u5341\u8fdb\u5236\u5e74\u4efd\uff08\u503c\u4ece0\u523099\uff09<br \/>\n%Y \u5e26\u4e16\u7eaa\u90e8\u5206\u7684\u5341\u5236\u5e74\u4efd<br \/>\n%z\uff0c%Z \u65f6\u533a\u540d\u79f0\uff0c\u5982\u679c\u4e0d\u80fd\u5f97\u5230\u65f6\u533a\u540d\u79f0\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u3002<br \/>\n%% \u767e\u5206\u53f7<\/p>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; from datetime import time, tzinfo\n>&gt;&gt; class GMT1(tzinfo):\n... def utcoffset(self, dt):\n... return timedelta(hours=1)\n... def dst(self, dt):\n... return timedelta(0)\n... def tzname(self,dt):\n... return &quot;Europe\/Prague&quot;\n...\n>&gt;&gt; t = time(12, 10, 30, tzinfo=GMT1())\n>&gt;&gt; t # doctest: +ELLIPSIS\ndatetime.time(12, 10, 30, tzinfo=&lt;GMT1 object at 0x...&gt;)\n>&gt;&gt; gmt = GMT1()\n>&gt;&gt; t.isoformat()\n&#039;12:10:30+01:00&#039;\n>&gt;&gt; t.dst()\ndatetime.timedelta(0)\n>&gt;&gt; t.tzname()\n&#039;Europe\/Prague&#039;\n>&gt;&gt; t.strftime(&quot;%H:%M:%S %Z&quot;)\n&#039;12:10:30 Europe\/Prague&#039;\n>&gt;&gt; time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.localtime())\n&#039;2022-01-17 09:52:13&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>time.strftime()\u53ef\u4ee5\u7528\u6765\u83b7\u5f97\u5f53\u524d\u65f6\u95f4\uff0c\u53ef\u4ee5\u5c06\u65f6\u95f4\u683c\u5f0f\u5316\u4e3a\u5b57\u7b26\u4e32\u7b49\u7b49 \u683c\u5f0f\u547d\u4ee4\u5217\u5728\u4e0b\u9762\uff1a\uff08\u533a\u5206\u5927\u5c0f\u5199\uff09 %a \u661f\u671f\u51e0\u7684\u7b80\u5199    \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[35],"tags":[16],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/356"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":2,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":1009,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/1009"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}