{"id":19737,"date":"2018-12-30T15:30:48","date_gmt":"2018-12-30T06:30:48","guid":{"rendered":"https:\/\/www.hiro345.net\/blogs\/hiro345\/?p=19737"},"modified":"2019-01-04T18:59:06","modified_gmt":"2019-01-04T09:59:06","slug":"python3%e3%81%a7%e3%81%aedatetime%e3%80%81timezone%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6%e7%b0%a1%e5%8d%98%e3%81%ab%e3%81%be%e3%81%a8%e3%82%81%e3%81%a6%e3%81%bf","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/19737.html","title":{"rendered":"Python3\u3067\u306edatetime\u3001timezone\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u307f\u305f"},"content":{"rendered":"<p>Python3\u3067\u306edatetime\u3001timezone\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u3064\u3044\u3066\u306f\u3001pytz\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001\u6a19\u6e96\u306edatetime.timezone\u3082\u3042\u308b\u3088\u3046\u3067\u3059\u3002icalendar\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3063\u305f\u308a\u3059\u308b\u3068\u3001\u3053\u308c\u304cpytz\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u306e\u3067\u3001pytz\u3092\u4f7f\u3063\u3066\u3082\u3044\u3044\u3068\u306a\u308a\u305d\u3046\u3067\u3059\u304c\u3001\u6a19\u6e96\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3060\u3051\u3067\u4f55\u3068\u304b\u3057\u305f\u3044\u3068\u3044\u3046\u5834\u5408\u3082\u3042\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p><!--more--><br \/>\n\u7c21\u5358\u306a\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u52d5\u304b\u3057\u3066\u898b\u3066\u3044\u305f\u3089\u3001\u305d\u3053\u305d\u3053\u306e\u6642\u9593\u3092\u304b\u3051\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u500b\u4eba\u7684\u306b\u306f\u3001\u6574\u7406\u3067\u304d\u3066\u3088\u304b\u3063\u305f\u3067\u3059\u3002\u89e3\u8aac\u3092\u3064\u3051\u308b\u306e\u306f\u5c11\u3057\u5927\u5909\u305d\u3046\u3002<\/p>\n<p>\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u3001datetime.datetime.now()\u3084datetime.datetime()\u3067datetime\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3060\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u6307\u5b9a\u304c\u306a\u3044\u5834\u5408\u306fLOCALE\u306e\u74b0\u5883\u306b\u4f9d\u5b58\u3059\u308b\u3088\u3046\u306b\u306a\u308b\u306e\u3067\u3001\u624b\u5143\u306e\u65e5\u672c\u8a9e\u74b0\u5883\u3067\u306f\u81ea\u52d5\u3067Asia\/Tokyo\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3068\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3057\u305f\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4e0b\u8a18\u306b\u306a\u308a\u307e\u3059\u3002\u5c11\u3057\u305a\u3064\u78ba\u8a8d\u3057\u305f\u3044\u3053\u3068\u3092\u8ffd\u52a0\u3057\u3066\u3044\u3063\u305f\u3089\u3001\u7d50\u69cb\u9577\u304f\u306a\u308a\u307e\u3057\u305f&#8230;<\/p>\n<pre class=\"brush: python; gutter: true\">\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nfrom datetime import datetime, date, timedelta, timezone\r\nimport pytz\r\nimport re\r\n\r\n# \u30bf\u30a4\u30e0\u30be\u30fc\u30f3 \uff08Python 3.2 \u4ee5\u964d\u3067\u8ffd\u52a0\u3055\u308c\u305f, \u6642\u9593\u5dee\u3067\u306e\u6307\u5b9a\u304c\u5fc5\u8981\uff09\r\ntz_jst = timezone(timedelta(hours=+9), &#039;JST&#039;)\r\n\r\n# pytz\u306b\u3088\u308b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3 \uff08timezone\u3068\u540c\u3058\u304f\u62bd\u8c61\u57fa\u5e95\u30af\u30e9\u30b9tzinfo\u306e\u5b9f\u88c5\uff09\r\npytz_jst = pytz.timezone(&#039;Asia\/Tokyo&#039;)\r\n\r\n# \u73fe\u5728\u6642\u523b\r\ncurrent_time = datetime.now()  # \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306fNone\u306b\u306a\u308b\r\ncurrent_time_utc = datetime.now(timezone.utc)\r\n# +09:00(JST)\u3067\u306e\u73fe\u5728\u6642\u523b\r\ncurrent_time_tz_jst = datetime.now(tz_jst)\r\n# Asia\/Tokyo(pytz\u5229\u7528)\u3067\u306e\u73fe\u5728\u6642\u523b\r\ncurrent_time_pytz_jst = datetime.now(pytz_jst)\r\n\r\n# \u6642\u523b\u306e\u8868\u793a\u3002\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u6307\u5b9a\u3057\u306a\u3044\u306a\u3089 str() \u304c\u4f7f\u3048\u308b\u3002\r\nprint(&quot;current_time:&quot; + str(current_time))\r\nprint(&quot;current_time_utc:&quot; + str(current_time_utc))\r\nprint(&quot;current_time_tz_jst:&quot; + str(current_time_tz_jst))\r\nprint(&quot;current_time_pytz_jst:&quot; + str(current_time_pytz_jst))\r\n\r\n# \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u8868\u793a\r\nprint(&quot;current_time.tzname():&quot; + str(current_time.tzname()))\r\nprint(&quot;current_time_utc.tzname():&quot; + str(current_time_utc.tzname()))\r\nprint(&quot;current_time_tz_jst.tzname():&quot; + str(current_time_tz_jst.tzname()))\r\nprint(&quot;current_time_pytz_jst.tzname():&quot; + str(current_time_pytz_jst.tzname()))\r\n\r\n# \u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306e\u8868\u793a\r\nprint(&quot;current_time.timestamp():&quot; + str(current_time.timestamp()))\r\nprint(&quot;current_time_utc.timestamp():&quot; + str(current_time_utc.timestamp()))\r\nprint(&quot;current_time_tz_jst.timestamp():&quot; +\r\n      str(current_time_tz_jst.timestamp()))\r\nprint(&quot;current_time_pytz_jst.timestamp():&quot; +\r\n      str(current_time_pytz_jst.timestamp()))\r\n\r\n# \u6587\u5b57\u5217\u3078\u306e\u5909\u63db\r\nprint(&#039;datetime.strftime()&#039;)\r\nprint(&#039;    current_time, current_time_utc, current_time_tz_jst, current_time_pytz_jst&#039;)\r\nfor t in (current_time, current_time_utc, current_time_tz_jst, current_time_pytz_jst,):\r\n    dt_str = datetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;)\r\n    print(&quot;datetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;):&quot; + dt_str)\r\n\r\n# datetime.strftime()\u3067\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u6307\u5b9a\r\nprint(&quot;datetime.strftime(current_time_tz_jst, &#039;%z&#039;):&quot; +\r\n      datetime.strftime(current_time_tz_jst, &#039;%z&#039;))\r\nprint(&quot;datetime.strftime(current_time_tz_jst, &#039;%Z&#039;):&quot; +\r\n      datetime.strftime(current_time_tz_jst, &#039;%Z&#039;))\r\n\r\n# ISO8601 \u57fa\u672c\u5f62\u5f0f\u306e\u65b9\u304c\u6587\u5b57\u6570\u304c\u5c11\u306a\u3044\u3002\u62e1\u5f35\u5f62\u5f0f\u306f\u8996\u8a8d\u6027\u3092\u9ad8\u3081\u305f\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\r\ndt_str = datetime.strftime(current_time_utc, &#039;%Y%m%dT%H%M%SZ&#039;)  # UTC\u6642\u523b\u306b\u306fZ\u3092\u3064\u3051\u308b\r\nprint(&quot;ISO8601 \u57fa\u672c\u5f62\u5f0f current_time_utc:&quot; + dt_str)\r\ndt_str = datetime.strftime(\r\n    current_time_utc, &#039;%Y-%m-%dT%H:%M:%SZ&#039;)  # UTC\u6642\u523b\u306b\u306fZ\u3092\u3064\u3051\u308b\r\nprint(&quot;ISO8601 \u62e1\u5f35\u5f62\u5f0f current_time_utc:&quot; + dt_str)\r\ndt_str = datetime.strftime(current_time_tz_jst, &#039;%Y%m%dT%H%M%S%z&#039;)\r\nprint(&quot;ISO8601 \u57fa\u672c\u5f62\u5f0f current_time_tz_jst:&quot; + dt_str)\r\ndt_str = datetime.strftime(current_time_tz_jst, &#039;%Y-%m-%dT%H:%M:%S%z&#039;)\r\nprint(&quot;ISO8601 \u62e1\u5f35\u5f62\u5f0f current_time_tz_jst:&quot; +\r\n      &#039;{0}:{1}&#039;.format(dt_str[:22], dt_str[22:]))\r\n\r\n# \u6642\u523b\u306e\u60c5\u5831\u3092\u53d6\u5f97\r\nprint(&quot;current_time.year:&quot; + str(current_time.year))\r\nprint(&quot;current_time.month:&quot; + str(current_time.month))\r\nprint(&quot;current_time.day:&quot; + str(current_time.day))\r\nprint(&quot;current_time.hour:&quot; + str(current_time.hour))\r\nprint(&quot;current_time.minute:&quot; + str(current_time.minute))\r\nprint(&quot;current_time.second:&quot; + str(current_time.second))\r\nprint(&quot;current_time.microsecond:&quot; + str(current_time.microsecond))\r\n# 0: \u6708, 1: \u706b, 2: \u6c34, 3: \u6728, 4: \u91d1, 5: \u571f, 6: \u65e5\r\nprint(&quot;current_time.weekday():&quot; + str(current_time.weekday()))\r\n\r\n# \u6642\u9593\u306e\u8a08\u7b97  minutes, seconds \u3082\u4f7f\u3048\u307e\u3059\r\nafter_a_week = current_time + timedelta(weeks=1)\r\nbefore_10_days = current_time - timedelta(days=10)\r\nafter_10_hours = current_time + timedelta(hours=10)\r\nprint(&quot;after_a_week:&quot; + str(after_a_week))\r\nprint(&quot;before_10_days:&quot; + str(before_10_days))\r\nprint(&quot;after_10_hours:&quot; + str(after_10_hours))\r\n\r\n# 2\u6642\u959330\u5206\u5f8c\u306e\u6642\u523b\u30c7\u30fc\u30bf\u3092\u4f5c\u3063\u3066\u3001\u5dee\u5206\u3092\u78ba\u8a8d\r\nstart_time = current_time\r\nend_time = current_time + timedelta(hours=2, minutes=30)\r\nduration = end_time - start_time  # type(duration) is datetime.timedelta\r\nduration_minutes = int(duration.seconds \/ 60)\r\nprint(&quot;duration_minutes=end_time-start_time: &quot; +\r\n      str(duration_minutes) + &#039; = &#039; + str(end_time) + &#039; - &#039; + str(start_time))\r\n\r\n# \u6587\u5b57\u5217\u304b\u3089\u306e\u5909\u63db\r\ndt_str = &#039;2018-12-30 12:34:56&#039;\r\ndt = datetime.strptime(dt_str, &#039;%Y-%m-%d %H:%M:%S&#039;)\r\nprint(&quot;2018-12-30 12:34:56 -&gt; &#039;%Y-%m-%d %H:%M:%S&#039;:&quot; + str(dt))\r\ndt_iso8601_utc_str = &#039;20181230T123456Z&#039;\r\n# \u6700\u5f8c\u306eZ\u3092UTC\u306b\u5909\u63db\u3057\u3066strptime\u3067%Z\u3092\u4f7f\u3046\u3068\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u60c5\u5831\u304c\u3064\u304b\u306a\u3044\r\ndt_str = dt_iso8601_utc_str.replace(&#039;Z&#039;, &#039;+0000&#039;)\r\ndt = datetime.strptime(dt_str, &#039;%Y%m%dT%H%M%S%z&#039;)\r\nprint(&quot;20181230T123456Z -&gt; %Y%m%dT%H%M%S%z&#039;:&quot; + str(dt))\r\nprint(&quot;dt.tzname():&quot; + str(dt.tzname()))\r\ndt_str = &#039;2018-12-30T12:34:56+09:00&#039;  # &#039;20181230T123456+0900&#039;\u306b\u3057\u3066\u304b\u3089\u51e6\u7406\u304c\u7c21\u5358\r\n# dt_iso8601_str = dt_str.replace(&#039;-&#039;, &#039;&#039;).replace(&#039;:&#039;, &#039;&#039;) \u3067\u3082\u826f\u3044\r\ndt_iso8601_str = re.sub(&#039;[-:]&#039;, &#039;&#039;, dt_str)\r\ndt = datetime.strptime(dt_iso8601_str, &#039;%Y%m%dT%H%M%S%z&#039;)\r\nprint(&quot;2018-12-30T12:34:56+09:00 -&gt; 20181230T123456+0900 -&gt; &#039;%Y%m%dT%H%M%S%z&#039;:&quot; + str(dt))\r\nprint(&quot;dt.tzname():&quot; + str(dt.tzname()))\r\n\r\n# datetime.datetime\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210, locale\u4f9d\u5b58\u3092\u306a\u304f\u3059\u306b\u306ftzinfo\u306f\u3064\u3051\u305f\u65b9\u304c\u826f\u3044\r\ndt = datetime(2018, 12, 30, tzinfo=timezone.utc)  # \u5e74\u6708\u65e5\u306f\u5fc5\u9808\r\nprint(&quot;datetime(2018, 12, 30, tzinfo=timezone.utc):&quot; + str(dt))\r\ndt = datetime(2018, 12, 30, 12, 34, 56, tzinfo=tz_jst)  # \u6642\u3001\u5206\u3001\u79d2\u3082\u6307\u5b9a\u53ef\u80fd\r\nprint(&quot;datetime(2018, 12, 30, 12, 34, 56, tzinfo=tz_jst):&quot; + str(dt))\r\n\r\n# datetime.datetime\u304b\u3089datetime.date\u3078\u306e\u5909\u63db\r\ndate_obj = date(dt.year, dt.month, dt.day)\r\nprint(&quot;date_obj:&quot; + str(date_obj))\r\n\r\n# \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u5909\u66f4\r\nprint(&#039;current_time_tz_jst.astimezone(timezone.utc)&#039;)\r\ncurrent_time_astimezone_utc = current_time_tz_jst.astimezone(timezone.utc)\r\nprint(&quot;current_time_astimezone_utc.tzname():&quot; +\r\n      str(current_time_astimezone_utc.tzname()))\r\nprint(&quot;current_time_astimezone_utc:&quot; + str(current_time_astimezone_utc))\r\n\r\n# \u6642\u523b\u60c5\u5831\u306b\u5f71\u97ff\u3092\u4e0e\u3048\u305a\u306b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u5909\u66f4\u3059\u308b\u306b\u306f replace()\u3092\u4f7f\u3046\r\ncurrent_time_tz_replace_utc = current_time_tz_jst.replace(tzinfo=timezone.utc)\r\nprint(&quot;current_time_tz_replace_utc.tzname():&quot; +\r\n      str(current_time_tz_replace_utc.tzname()))\r\nprint(&quot;current_time_tz_replace_utc:&quot; + str(current_time_tz_replace_utc))\r\n<\/pre>\n<p>\u3053\u308c\u3092\u3001sample.py\u3068\u3044\u3046\u540d\u524d\u3067\u4fdd\u5b58\u3057\u305f\u3068\u3057\u307e\u3059\u3002pytz\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304b\u3089\u5b9f\u884c\u3057\u307e\u3059\u3002\u500b\u4eba\u7684\u306b\u306fvenv\u3092\u3088\u304f\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u306e\u624b\u9806\u3060\u3068\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002venv\/bin\/activate \u3067Python\u4eee\u60f3\u74b0\u5883\u3092\u6709\u52b9\u306b\u3057\u3066\u3001deactivate \u3067Python\u4eee\u60f3\u74b0\u5883\u3092\u629c\u3051\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\n$ python3 -m venv venv\r\n$ . venv\/bin\/activate\r\n(venv)$ pip install pytz\r\n(venv)$ python sample.py\r\n(venv)$ TZ=UTC python sample.py\r\n(venv)$ deactivate\r\n<\/pre>\n<p>TZ=UTC\u3092\u3064\u3051\u3066\u5b9f\u884c\u3059\u308b\u3068\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306e\u51e6\u7406\u7d50\u679c\u304c\u3069\u3046\u306a\u308b\u304b\u3001\u308f\u304b\u308b\u306f\u305a\u3067\u3059\u3002\u53c2\u8003\u307e\u3067\u306b\u3002<\/p>\n<p>\u3055\u3066\u3001TZ=UTC\u3092\u3064\u3051\u306a\u3044\u5834\u5408\u306e\u5b9f\u884c\u7d50\u679c\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u30b3\u30fc\u30c9\u3068\u7d50\u679c\u3092\u898b\u6bd4\u3079\u308b\u3068\u3001\u3044\u308d\u3044\u308d\u3068\u308f\u304b\u3063\u3066\u304d\u307e\u3059\u3002datetime.datetime.now()\u3067\u4f5c\u6210\u3057\u305fdatetime.datetime\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306etimestamp()\u306e\u5024\u306f\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u6307\u5b9a\u3057\u3066\u3082\u3057\u306a\u304f\u3066\u3082\u540c\u3058\u306b\u306a\u308b\u306e\u3067\u3059\u306d\u3002\u305f\u3060\u3001datetime.datetime.tzname()\u3067\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u5024\u304c\u3068\u308c\u306a\u3044\u3068\u3001\u4ed6\u306e\u30b7\u30b9\u30c6\u30e0\u3068\u304b\u3001icalendar\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u51e6\u7406\u3092\u3057\u305f\u308a\u3059\u308b\u3068\u304d\u306b\u3001\u4f55\u304b\u3068\u4e0d\u4fbf\u306b\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306f\u6307\u5b9a\u3057\u3066\u304a\u3044\u305f\u65b9\u304c\u826f\u3055\u305d\u3046\u3002<\/p>\n<pre class=\"brush: bash; gutter: true\">\r\ncurrent_time:2018-12-30 14:42:14.228792\r\ncurrent_time_utc:2018-12-30 05:42:14.228799+00:00\r\ncurrent_time_tz_jst:2018-12-30 14:42:14.228802+09:00\r\ncurrent_time_pytz_jst:2018-12-30 14:42:14.228802+09:00\r\ncurrent_time.tzname():None\r\ncurrent_time_utc.tzname():UTC\r\ncurrent_time_tz_jst.tzname():JST\r\ncurrent_time_pytz_jst.tzname():JST\r\ncurrent_time.timestamp():1546148534.228792\r\ncurrent_time_utc.timestamp():1546148534.228799\r\ncurrent_time_tz_jst.timestamp():1546148534.228802\r\ncurrent_time_pytz_jst.timestamp():1546148534.228802\r\ndatetime.strftime()\r\n    current_time, current_time_utc, current_time_tz_jst, current_time_pytz_jst\r\ndatetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;):2018-12-30 14:42:14\r\ndatetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;):2018-12-30 05:42:14\r\ndatetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;):2018-12-30 14:42:14\r\ndatetime.strftime(t, &#039;%Y-%m-%d %H:%M:%S&#039;):2018-12-30 14:42:14\r\ndatetime.strftime(current_time_tz_jst, &#039;%z&#039;):+0900\r\ndatetime.strftime(current_time_tz_jst, &#039;%Z&#039;):JST\r\nISO8601 \u57fa\u672c\u5f62\u5f0f current_time_utc:20181230T054214Z\r\nISO8601 \u62e1\u5f35\u5f62\u5f0f current_time_utc:2018-12-30T05:42:14Z\r\nISO8601 \u57fa\u672c\u5f62\u5f0f current_time_tz_jst:20181230T144214+0900\r\nISO8601 \u62e1\u5f35\u5f62\u5f0f current_time_tz_jst:2018-12-30T14:42:14+09:00\r\ncurrent_time.year:2018\r\ncurrent_time.month:12\r\ncurrent_time.day:30\r\ncurrent_time.hour:14\r\ncurrent_time.minute:42\r\ncurrent_time.second:14\r\ncurrent_time.microsecond:228792\r\ncurrent_time.weekday():6\r\nafter_a_week:2019-01-06 14:42:14.228792\r\nbefore_10_days:2018-12-20 14:42:14.228792\r\nafter_10_hours:2018-12-31 00:42:14.228792\r\nduration_minutes=end_time-start_time: 150 = 2018-12-30 17:12:14.228792 - 2018-12-30 14:42:14.228792\r\n2018-12-30 12:34:56 -&gt; &#039;%Y-%m-%d %H:%M:%S&#039;:2018-12-30 12:34:56\r\n20181230T123456Z -&gt; %Y%m%dT%H%M%S%z&#039;:2018-12-30 12:34:56+00:00\r\ndt.tzname():UTC\r\n2018-12-30T12:34:56+09:00 -&gt; 20181230T123456+0900 -&gt; &#039;%Y%m%dT%H%M%S%z&#039;:2018-12-30 12:34:56+09:00\r\ndt.tzname():UTC+09:00\r\ndatetime(2018, 12, 30, tzinfo=timezone.utc):2018-12-30 00:00:00+00:00\r\ndatetime(2018, 12, 30, 12, 34, 56, tzinfo=tz_jst):2018-12-30 12:34:56+09:00\r\ndate_obj:2018-12-30\r\ncurrent_time_tz_jst.astimezone(timezone.utc)\r\ncurrent_time_astimezone_utc.tzname():UTC\r\ncurrent_time_astimezone_utc:2018-12-30 05:42:14.228802+00:00\r\ncurrent_time_tz_replace_utc.tzname():UTC\r\ncurrent_time_tz_replace_utc:2018-12-30 14:42:14.228802+00:00\r\n<\/pre>\n<p>ISO8601\u306e\u57fa\u672c\u5f62\u5f0f\u30fb\u62e1\u5f35\u5f62\u5f0f\u306f\u826f\u304f\u4f7f\u3046\u306e\u3067\u3001datetime.datetime\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u306e\u76f8\u4e92\u5909\u63db\u306b\u3064\u3044\u3066\u3001\u3069\u3046\u3059\u308b\u304b\u3082\u78ba\u8a8d\u3057\u3066\u3042\u308a\u307e\u3059\u3002\u6c4e\u7528\u7684\u306b\u4f5c\u6210\u3059\u308b\u306e\u306f\u3061\u3087\u3063\u3068\u9762\u5012\u305d\u3046\u3067\u3059\u304c\u3001UTC, Asia\/Tokyo, JST, Japan \u3060\u3051\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u306a\u3089\u3001\u96e3\u3057\u304f\u306f\u306a\u3055\u305d\u3046\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python3\u3067\u306edatetime\u3001timezone\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306b\u3064\u3044\u3066\u306f\u3001pytz\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001\u6a19\u6e96\u306edatetime.timezone\u3082\u3042\u308b\u3088\u3046\u3067\u3059\u3002ica &hellip; <a href=\"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/19737.html\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[694,60,1396],"class_list":["post-19737","post","type-post","status-publish","format-standard","hentry","category-program","tag-datetime","tag-python","tag-timezone"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/19737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=19737"}],"version-history":[{"count":3,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/19737\/revisions"}],"predecessor-version":[{"id":19751,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/19737\/revisions\/19751"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=19737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=19737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=19737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}