{"id":1472,"date":"2022-07-12T20:22:26","date_gmt":"2022-07-12T20:22:26","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=1472"},"modified":"2022-07-15T07:00:15","modified_gmt":"2022-07-15T07:00:15","slug":"sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/","title":{"rendered":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50"},"content":{"rendered":"\n<script type=\"text\/javascript\" src=\"https:\/\/momentjs.com\/downloads\/moment.js\">\n<\/script>\n\n<script type=\"text\/javascript\" src=\"https:\/\/momentjs.com\/downloads\/moment-timezone-with-data.js\">\n<\/script>\n    \n<style>\n    .container {\n        display: grid;\n        grid-template-columns: 50% 50%;\n        padding: 1%;\n        border: 0px solid blue;\n    }\n    .inner {\n        padding: 1%;\n        border: 0px solid blue;\n    }\n    #sf,#bj,#sfapm,#bjapm,#sfyr,#bjyr {\n        color: green;\n        font-family: 'Orbitron', sans-serif;\n    }\n<\/style>\n\n<link href=\"https:\/\/fonts.googleapis.com\/css?family=Orbitron\" rel=\"stylesheet\" type=\"text\/css\">\n\n    <div class=\"container\">\n        <div class=\"inner\">\n            <h1>San Francisco Time ??<\/h1>\n        <\/div>\n        <div class=\"inner\">\n            <h1>Beijing Time ??<\/h1>            \n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"sf\"><\/h2>\n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"bj\"><\/h2>\n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"sfapm\"><\/h2>\n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"bjapm\"><\/h2>\n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"sfyr\"><\/h2>\n        <\/div>\n        <div class=\"inner\">\n            <h2 id=\"bjyr\"><\/h2>\n        <\/div>\n    <\/div>\n\n    <script>\n        const sf = document.getElementById(\"sf\");\n        const bj = document.getElementById(\"bj\");\n\n        const sfapm = document.getElementById(\"sfapm\");\n        const bjapm = document.getElementById(\"bjapm\");\n\n        const sfyr = document.getElementById(\"sfyr\");\n        const bjyr = document.getElementById(\"bjyr\");\n\n        const format = 'hh:mm:ss a z YYYY-MM-DD';\n        const formatTime = 'hh:mm:ss';\n        const formatApmZone = 'a z';\n        const formatYear = 'YYYY-MM-DD';\n\n        function update() {\n            const sftime = moment()\n                .tz('America\/Los_Angeles');\n\n            const bjtime = moment()\n                .tz('Asia\/Shanghai');\n\n            sf.textContent= sftime.format(formatTime);\n            bj.textContent= bjtime.format(formatTime);\n\n            sfapm.textContent= sftime.format(formatApmZone);\n            bjapm.textContent= bjtime.format(formatApmZone);\n\n            sfyr.textContent= sftime.format(formatYear);\n            bjyr.textContent= bjtime.format(formatYear);\n        }\n\n        update();\n        window.setInterval(update, 1000)\n    <\/script>\n\n\n\n<p>\u628a\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u6e7e\u533a9:00am\uff0c\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\uff0c\u5e94\u8be5\u662f\u5f88\u7b80\u5355\u7684\u95ee\u9898\u3002\u7528Python\u505a\u65f6\u533a\u8f6c\u6362\u597d\u50cf\u633a\u9ebb\u70e6\u7684\uff0c\u5bb9\u6613\u51fa\u9519\u3002Google\u51fa\u6765\u7684\u524d\u51e0\u6761\u7ed3\u679c\u90fd\u4e0d\u662f\u5f88\u8ba9\u4eba\u6ee1\u610f\uff0c\u672c\u6587\u603b\u7ed3\u6211\u6d4b\u8bd5\u8fc7\u53ef\u9760\u53ef\u884c\u4e0d\u592a\u590d\u6742\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5bb9\u6613\u51fa\u9519\u7684\u5730\u65b9\u3002<\/p>\n\n\n\n<p>\u5148\u4e0a\u53ef\u884c\u7684Python\u4f8b\u5b50\uff0c\u628a\u4e09\u85e9\uff08SF\uff09\u6e7e\u533a\u65f6\u95f49am, \u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u5317\u4eac\u65f6\u95f4\uff0c\u7528\u4e86<code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">datetime<\/code>\u548c<code data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">pytz<\/code>\u3002\u5148\u6784\u9020\u4e00\u4e2a\u6e7e\u533a\u65f6\u95f4\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u8f6c\u5316\u6210\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from pytz import timezone\nfrom datetime import datetime\n\nbjtz = timezone('Asia\/Harbin')\nsftz = timezone('US\/Pacific')\n\ndt9amsf = sftz.localize(datetime(2022, 7, 11, 9, 0))\ndt9amsf2bj = dt9amsf.astimezone(bjtz)\n<\/pre>\n\n\n\n<p>\u52a0\u4e0a\u6ce8\u89e3\u548cdebug\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from pytz import timezone\nfrom datetime import datetime\n\nformat = '%Y-%m-%d %H:%M:%S %Z %z'\n\nbjtz = timezone('Asia\/Harbin')\nsftz = timezone('US\/Pacific')\n\n# construct SF 9am datetime object\ndt9amsf = sftz.localize(datetime(2022, 7, 11, 9, 0))\n\n# for debug\nprint(dt9amsf.strftime(format)) # 2022-07-11 09:00:00, 09:00AM PDT -0700\nprint(dt9amsf.timestamp()) #1657555200.0\n\n# Convert to Beijing time\ndt9amsf2bj = dt9amsf.astimezone(bjtz)\n# debug\nprint(dt9amsf2bj.strftime(format)) #2022-07-12 00:00:00, 12:00AM CST +0800\n\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u5efa\u7acb\u7684\u6e7e\u533a\u65f6\u95f4\u65f6\u533a\u4e3a-0700\u800c\u5317\u4eac\u65f6\u95f4\u4e3a0800\uff0c\u53ef\u4ee5\u9a8c\u8bc1\u6e7e\u533a\u548c\u4e2d\u56fd\u65f6\u5dee\u4e3a15\u5c0f\u65f6\u3002<\/p>\n\n\n\n<h2>\u65f6\u533a\u884c\u8bdd\u89e3\u91ca<\/h2>\n\n\n\n<p>\u5168\u7403\u6807\u51c6\u65f6\u95f4\u7528\u7684\u662f\u4f4d\u4e8e\u82f1\u56fd\u7684\u683c\u6797\u5a01\u6cbb\u65f6\u95f4(GMT, Greenwich Mean Time)\u3002\u56e0\u4e3a\u4ee5\u524d\u683c\u6797\u5a01\u6cbb\u5929\u6587\u53f0\u662f\u4e16\u754c\u4e2d\u5fc3\uff0c\u672c\u521d\u5b50\u5348\u7ebf\u6216\u80050\u5ea6\u7ecf\u7ebf\u5c31\u5b9a\u4e49\u4e3a\u7a7f\u8fc7\u5b83\u7684\u7ecf\u7ebf\u3002\u7136\u540e\u53c8\u6709\u4e86\u4e00\u4e2a\u53eb\u4e16\u754c\u534f\u8c03\u65f6\u95f4\u7684\u4e1c\u897f\uff08UTC, Coordinated Universal Time\uff09\u3002\u8fd9\u4e2a\u548cGMT\u57fa\u672c\u4e00\u81f4\uff0c\u5927\u6982\u5c31\u662f\u5317\u4eac\u8bdd\u548c\u666e\u901a\u8bdd\u7684\u533a\u522b\u5427\u3002\u5317\u4eac\u5728Greenwich\u7684\u4e1c\u8fb9\uff0c\u65f6\u95f4\u9886\u5148GMT\/UTC 8\u5c0f\u65f6\uff0c\u6240\u4ee5\u53eb\u4e1c\u516b\u533a\uff0c\u4ee3\u53f70800\u3002\u800c\u6e7e\u533a\u5728\u683c\u6797\u5a01\u6cbb\u7684\u897f\u8fb9\uff0c\u65f6\u95f4\u6ede\u540e7\u4e2a\u5c0f\u65f6\uff08\u7f8e\u56fd\u56fd\u4f1a\u901a\u8fc7\u4e86\u6c38\u4e45\u4f7f\u7528\u590f\u4ee4\u65f6\u6cd5\u6848\uff09\uff0c\u6240\u4ee5\u53eb\u897f7\u533a\uff0c\u4ee3\u53f7-0700\u3002\u800c\u4e24\u5730\u65f6\u5dee\u4e3a7+9=15\uff0c\u5317\u4eac\u65f6\u95f4\u6bd4\u6e7e\u533a\u65f6\u95f4\u9886\u514815\u4e2a\u5c0f\u65f6\u3002<\/p>\n\n\n\n<p>\u540c\u7406\uff0c\u65e5\u672c\u548c\u97e9\u56fd\u4f4d\u4e8e\u4e1c9\u533a\uff0c\u4ee3\u53f7\u4e3a0900\uff0c\u90a3\u4e48\u65f6\u95f4\u5c31\u6bd4\u4e3a\u4e0e\u4e1c\u516b\u533a\u7684\u4e2d\u56fd\u65e91\u5c0f\u65f6\u3002<\/p>\n\n\n\n<h2>\u5f53\u5730\u771f\u5b9e\u65f6\u95f4\u548c\u7ea6\u5b9a\u6807\u51c6\u65f6\u95f4<\/h2>\n\n\n\n<p>\u4e00\u4e2a\u5730\u65b9\u7684\u771f\u5b9e\u65f6\u95f4\u53ea\u53d6\u51b3\u4e8e\u592a\u9633\u76f8\u5bf9\u5f53\u5730\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u53d6\u51b3\u4e8e\u5f53\u5730\u7ecf\u5ea6\u3002\u4f46\u662f\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6bcf\u4e2a\u56fd\u5bb6\u53ef\u4ee5\u4eba\u4e3a\u89c4\u5b9a\u7528\u4ec0\u4e48\u65f6\u95f4\u3002\u6bd4\u5982\u6574\u4e2a\u4e2d\u56fd\u867d\u7136\u8de8\u4e86\u51e0\u4e2a\u7eac\u5ea6\uff0c\u786e\u4eba\u4e3a\u89c4\u5b9a\u4e86\u5404\u5730\u90fd\u4f7f\u7528\u5317\u4eac\u65f6\u95f4\u3002\u65b0\u52a0\u5761\u771f\u5b9e\u65f6\u95f4\u5e94\u8be5\u4e3a0655\uff0c<a href=\"https:\/\/zh.m.wikipedia.org\/zh-cn\/%E6%96%B0%E5%8A%A0%E5%9D%A1%E6%A8%99%E6%BA%96%E6%99%82%E9%96%93\">\u786e\u89c4\u5b9a\u4f7f\u75280800<\/a>\uff0c\u4e5f\u8bb8\u662f\u548c\u5927\u4e2d\u534e\u533a\u4fdd\u6301\u4e00\u81f4\u6bd4\u8f83\u65b9\u4fbf\u3002<\/p>\n\n\n\n<p>\u56de\u5230Python\u4e0a\uff0c\u8fd9\u4e5f\u6b63\u662fpytz\u5305\u7684\u4e00\u4e9b\u5751\u7684\u6765\u6e90\u3002pytz\u7528\u7684\u662f\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\uff0c\u800c\u4eba\u4eec\u771f\u6b63\u4f7f\u7528\u7684\u662f\u5f53\u5730\u6cd5\u5f8b\u7ea6\u5b9a\u7684\u65f6\u95f4\uff0c\u8fd9\u4e24\u8005\u662f\u6709\u5dee\u522b\u7684\u3002<\/p>\n\n\n\n<h2>Python datetime\u4e0d\u8bbe\u65f6\u533a\u662f\u4ec0\u4e48\u65f6\u95f4\uff1f<\/h2>\n\n\n\n<p>\u5982\u679c\u65b0\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61\uff0c\u4e0d\u8bbe\u65f6\u533a\u7684\u8bdd\uff0c\u4f1a\u662f\u5f53\u5730\u65f6\u95f4\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from datetime import datetime\n\ndt = datetime(2022, 7, 1)\nformat = '%Y-%m-%d %H:%M:%S %Z %z'\nprint(dt.strftime(format)) # => '2022-07-01 00:00:00  ' time zone missing\nprint(dt.timestamp()) # => 1656658800.0<\/pre>\n\n\n\n<p>\u7528<a href=\"https:\/\/www.epochconverter.com\/\">epochconverter<\/a>\u8f6c\u63621656658800.0\uff0c\u6b63\u662f\u6e7e\u533a\u65f6\u95f42022-07-01 00:00:00<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1264\" height=\"394\" src=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2022\/07\/image-5.png\" alt=\"\" class=\"wp-image-1579\"\/><\/figure>\n\n\n\n<p>\u5982\u679creplace\u4e86timezone\uff0c\u5c31\u628a\u5e95\u4e0b\u7684timestamp\u53d8\u4e86\uff0c\u800c\u4e0d\u662f\u4fdd\u6301timestamp\u800c\u6539\u53d8\u65f6\u95f4\u8868\u793a\u5f62\u5f0f\uff08\u65e5\u671f\uff0c\u5c0f\u65f6\/\u5206\/\u79d2\uff09\u3002\u6240\u4ee5replace(tzinfo=&#8230;)\u5e76\u4e0d\u662f\u505a\u65f6\u533a\u53d8\u6362\u3002\u800c\u4e14\u6ce8\u610f\u4e0b\u9762\u4f8b\u5b50\u91cc\u4e0a\u6d77\u65f6\u95f4\u662f0806\uff0c\u5e76\u4e0d\u662f0800\uff0c\u5e94\u8be5\u7528\u4e86\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\u800c\u4e0d\u662f\u6cd5\u5b9a\u65f6\u95f4\u3002\u8fd9\u4e2a\u5730\u7406\u65f6\u95f4\u5728\u751f\u6d3b\u4e2d\u57fa\u672c\u6ca1\u7528\uff0c\u8fd9\u4e2apytz\u7684\u5751\u4e4b\u4e00\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"classic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">bjdt = dt.replace(tzinfo=bjtz) # bjdt is datetime.datetime(2022, 7, 1, 0, 0, tzinfo=&lt;DstTzInfo 'Asia\/Harbin' LMT+8:06:00 STD>), dt itself is not changed\nprint(bjdt.strftime(format)) # => '2022-07-01 00:00:00 LMT +0806'\nbjdt.timestamp() # => 1656604440.0<\/pre>\n\n\n\n<h2>\u53c2\u8003<\/h2>\n\n\n\n<ul><li><a href=\"https:\/\/pythonmana.com\/2021\/08\/20210801235925524c.html\">Python3\u4e2ddatetime\u65f6\u533a\u8f6c\u6362\u4ecb\u7ecd\u4e0e\u8e29\u5751<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/presleyren\/p\/10310859.html\">python datetime\u65f6\u533a\u8f6c\u6362<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/zipxzf\/articles\/15335067.html\">\u6280\u5de7\uff1a\u7528datetime\u6a21\u5757\u5904\u7406\u65f6\u533a\u8f6c\u6362\uff0c\u4e0d\u8981\u7528time\u6a21\u5757<\/a><\/li><li><a href=\"https:\/\/blog.csdn.net\/xiongzaiabc\/article\/details\/81456542\">\u5c06UTC\u3001EST\u65f6\u533a\u7684\u65f6\u95f4\u8f6c\u5316\u6210\u5317\u4eac\u65f6\u95f4\uff08python\uff09<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/ajianbeyourself\/p\/11982529.html\">pytz\u5e93\u65f6\u533a\u7684\u5751\uff08\u8f6c\uff09<\/a><\/li><li><a href=\"https:\/\/developpaper.com\/the-solution-to-the-problem-of-pyrtz-formatting-beijing-time-over-6-minutes\/\">The Solution to the Problem of Pyrtz Formatting Beijing Time Over 6 Minutes<\/a><\/li><li><a href=\"https:\/\/blog.csdn.net\/qq_36530891\/article\/details\/90401346?utm_term=python%20%E6%97%B6%E5%8C%BA%E4%B8%8A%E6%B5%B7&amp;utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-0-90401346-null-null&amp;spm=3001.4430\">Python \u65f6\u95f4\u5904\u7406 \u65f6\u533a\u7684\u8f6c\u6362 \u65f6\u95f4\u7684\u8ba1\u7b97<\/a><\/li><li><a href=\"https:\/\/blog.csdn.net\/kz_java\/article\/details\/123615508?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-3-123615508-null-null.pc_agg_new_rank&amp;utm_term=python%20%E6%97%B6%E5%8C%BA%E4%B8%8A%E6%B5%B7&amp;spm=1000.2123.3001.4430\" target=\"_blank\" rel=\"noreferrer noopener\">\u3010<em>Python<\/em>\u3011<em>python<\/em>\u83b7\u53d6\u56fd\u5185\u65f6\u95f4\u53ca\u5176<em>\u65f6\u533a<\/em>&nbsp;pytz\u6a21\u5757\u7684\u4f7f\u7528<\/a><\/li><li><a href=\"https:\/\/medium.com\/swlh\/making-sense-of-timezones-in-python-16d8ae210c1c\">Making sense of timezones in Python<\/a><\/li><li><a href=\"http:\/\/pytz.sourceforge.net\/\">pytz &#8211; World Timezone Definitions for Python<\/a><\/li><li><a href=\"https:\/\/gist.github.com\/mjrulesamrat\/0c1f7de951d3c508fb3a20b4b0b33a98\">List of time zones &#8211; countryinfo.py on github<\/a><\/li><li><a href=\"https:\/\/pynative.com\/list-all-timezones-in-python\/\">List All TimeZones in Python<\/a><\/li><li><a href=\"https:\/\/www.codegrepper.com\/code-examples\/python\/how+to+convert+time+from+one+timezone+to+another+in+python\">\u201chow to convert time from one timezone to another in python\u201d Code Answer\u2019s<\/a>.  \u8fd9\u4e2a\u53ea\u6709now\u5230\u5176\u4ed6\u65f6\u533a\u65f6\u95f4\uff0c\u6ca1\u6709\u4efb\u610f\u65f6\u95f4<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>San Francisco Time ?? Beijing Time ?? \u628a\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u6e7e\u533a9:00am\uff0c\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\uff0c\u5e94\u8be5\u662f\u5f88\u7b80\u5355\u7684\u95ee\u9898\u3002\u7528Python\u505a\u65f6\u533a\u8f6c\u6362\u597d\u50cf\u633a\u9ebb\u70e6\u7684\uff0c\u5bb9\u6613\u51fa\u9519\u3002Google\u51fa\u6765\u7684\u524d\u51e0\u6761\u7ed3\u679c\u90fd\u4e0d\u662f\u5f88\u8ba9\u4eba\u6ee1\u610f\uff0c\u672c\u6587\u603b\u7ed3\u6211\u6d4b\u8bd5\u8fc7\u53ef\u9760\u53ef\u884c\u4e0d\u592a\u590d\u6742\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5bb9\u6613\u51fa\u9519\u7684\u5730\u65b9\u3002 \u5148\u4e0a\u53ef\u884c\u7684Python\u4f8b\u5b50\uff0c\u628a\u4e09\u85e9\uff08SF\uff09\u6e7e\u533a\u65f6\u95f49am, \u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u5317\u4eac\u65f6\u95f4\uff0c\u7528\u4e86datetime\u548cpytz\u3002\u5148\u6784\u9020\u4e00\u4e2a\u6e7e\u533a\u65f6\u95f4\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u8f6c\u5316\u6210\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\u3002 \u52a0\u4e0a\u6ce8\u89e3\u548cdebug\u4fe1\u606f\u3002 \u53ef\u4ee5\u770b\u5230\u5efa\u7acb\u7684\u6e7e\u533a\u65f6\u95f4\u65f6\u533a\u4e3a-0700\u800c\u5317\u4eac\u65f6\u95f4\u4e3a0800\uff0c\u53ef\u4ee5\u9a8c\u8bc1\u6e7e\u533a\u548c\u4e2d\u56fd\u65f6\u5dee\u4e3a15\u5c0f\u65f6\u3002 \u65f6\u533a\u884c\u8bdd\u89e3\u91ca \u5168\u7403\u6807\u51c6\u65f6\u95f4\u7528\u7684\u662f\u4f4d\u4e8e\u82f1\u56fd\u7684\u683c\u6797\u5a01\u6cbb\u65f6\u95f4(GMT, Greenwich Mean Time)\u3002\u56e0\u4e3a\u4ee5\u524d\u683c\u6797\u5a01\u6cbb\u5929\u6587\u53f0\u662f\u4e16\u754c\u4e2d\u5fc3\uff0c\u672c\u521d\u5b50\u5348\u7ebf\u6216\u80050\u5ea6\u7ecf\u7ebf\u5c31\u5b9a\u4e49\u4e3a\u7a7f\u8fc7\u5b83\u7684\u7ecf\u7ebf\u3002\u7136\u540e\u53c8\u6709\u4e86\u4e00\u4e2a\u53eb\u4e16\u754c\u534f\u8c03\u65f6\u95f4\u7684\u4e1c\u897f\uff08UTC, Coordinated Universal Time\uff09\u3002\u8fd9\u4e2a\u548cGMT\u57fa\u672c\u4e00\u81f4\uff0c\u5927\u6982\u5c31\u662f\u5317\u4eac\u8bdd\u548c\u666e\u901a\u8bdd\u7684\u533a\u522b\u5427\u3002\u5317\u4eac\u5728Greenwich\u7684\u4e1c\u8fb9\uff0c\u65f6\u95f4\u9886\u5148GMT\/UTC 8\u5c0f\u65f6\uff0c\u6240\u4ee5\u53eb\u4e1c\u516b\u533a\uff0c\u4ee3\u53f70800\u3002\u800c\u6e7e\u533a\u5728\u683c\u6797\u5a01\u6cbb\u7684\u897f\u8fb9\uff0c\u65f6\u95f4\u6ede\u540e7\u4e2a\u5c0f\u65f6\uff08\u7f8e\u56fd\u56fd\u4f1a\u901a\u8fc7\u4e86\u6c38\u4e45\u4f7f\u7528\u590f\u4ee4\u65f6\u6cd5\u6848\uff09\uff0c\u6240\u4ee5\u53eb\u897f7\u533a\uff0c\u4ee3\u53f7-0700\u3002\u800c\u4e24\u5730\u65f6\u5dee\u4e3a7+9=15\uff0c\u5317\u4eac\u65f6\u95f4\u6bd4\u6e7e\u533a\u65f6\u95f4\u9886\u514815\u4e2a\u5c0f\u65f6\u3002 \u540c\u7406\uff0c\u65e5\u672c\u548c\u97e9\u56fd\u4f4d\u4e8e\u4e1c9\u533a\uff0c\u4ee3\u53f7\u4e3a0900\uff0c\u90a3\u4e48\u65f6\u95f4\u5c31\u6bd4\u4e3a\u4e0e\u4e1c\u516b\u533a\u7684\u4e2d\u56fd\u65e91\u5c0f\u65f6\u3002 \u5f53\u5730\u771f\u5b9e\u65f6\u95f4\u548c\u7ea6\u5b9a\u6807\u51c6\u65f6\u95f4 \u4e00\u4e2a\u5730\u65b9\u7684\u771f\u5b9e\u65f6\u95f4\u53ea\u53d6\u51b3\u4e8e\u592a\u9633\u76f8\u5bf9\u5f53\u5730\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u53d6\u51b3\u4e8e\u5f53\u5730\u7ecf\u5ea6\u3002\u4f46\u662f\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6bcf\u4e2a\u56fd\u5bb6\u53ef\u4ee5\u4eba\u4e3a\u89c4\u5b9a\u7528\u4ec0\u4e48\u65f6\u95f4\u3002\u6bd4\u5982\u6574\u4e2a\u4e2d\u56fd\u867d\u7136\u8de8\u4e86\u51e0\u4e2a\u7eac\u5ea6\uff0c\u786e\u4eba\u4e3a\u89c4\u5b9a\u4e86\u5404\u5730\u90fd\u4f7f\u7528\u5317\u4eac\u65f6\u95f4\u3002\u65b0\u52a0\u5761\u771f\u5b9e\u65f6\u95f4\u5e94\u8be5\u4e3a0655\uff0c\u786e\u89c4\u5b9a\u4f7f\u75280800\uff0c\u4e5f\u8bb8\u662f\u548c\u5927\u4e2d\u534e\u533a\u4fdd\u6301\u4e00\u81f4\u6bd4\u8f83\u65b9\u4fbf\u3002 \u56de\u5230Python\u4e0a\uff0c\u8fd9\u4e5f\u6b63\u662fpytz\u5305\u7684\u4e00\u4e9b\u5751\u7684\u6765\u6e90\u3002pytz\u7528\u7684\u662f\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\uff0c\u800c\u4eba\u4eec\u771f\u6b63\u4f7f\u7528\u7684\u662f\u5f53\u5730\u6cd5\u5f8b\u7ea6\u5b9a\u7684\u65f6\u95f4\uff0c\u8fd9\u4e24\u8005\u662f\u6709\u5dee\u522b\u7684\u3002 Python datetime\u4e0d\u8bbe\u65f6\u533a\u662f\u4ec0\u4e48\u65f6\u95f4\uff1f \u5982\u679c\u65b0\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61\uff0c\u4e0d\u8bbe\u65f6\u533a\u7684\u8bdd\uff0c\u4f1a\u662f\u5f53\u5730\u65f6\u95f4\u3002 \u7528epochconverter\u8f6c\u63621656658800.0\uff0c\u6b63\u662f\u6e7e\u533a\u65f6\u95f42022-07-01 00:00:00 \u5982\u679creplace\u4e86timezone\uff0c\u5c31\u628a\u5e95\u4e0b\u7684timestamp\u53d8\u4e86\uff0c\u800c\u4e0d\u662f\u4fdd\u6301timestamp\u800c\u6539\u53d8\u65f6\u95f4\u8868\u793a\u5f62\u5f0f\uff08\u65e5\u671f\uff0c\u5c0f\u65f6\/\u5206\/\u79d2\uff09\u3002\u6240\u4ee5replace(tzinfo=&#8230;)\u5e76\u4e0d\u662f\u505a\u65f6\u533a\u53d8\u6362\u3002\u800c\u4e14\u6ce8\u610f\u4e0b\u9762\u4f8b\u5b50\u91cc\u4e0a\u6d77\u65f6\u95f4\u662f0806\uff0c\u5e76\u4e0d\u662f0800\uff0c\u5e94\u8be5\u7528\u4e86\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\u800c\u4e0d\u662f\u6cd5\u5b9a\u65f6\u95f4\u3002\u8fd9\u4e2a\u5730\u7406\u65f6\u95f4\u5728\u751f\u6d3b\u4e2d\u57fa\u672c\u6ca1\u7528\uff0c\u8fd9\u4e2apytz\u7684\u5751\u4e4b\u4e00\u3002 \u53c2\u8003 Python3\u4e2ddatetime\u65f6\u533a\u8f6c\u6362\u4ecb\u7ecd\u4e0e\u8e29\u5751 python datetime\u65f6\u533a\u8f6c\u6362 \u6280\u5de7\uff1a\u7528datetime\u6a21\u5757\u5904\u7406\u65f6\u533a\u8f6c\u6362\uff0c\u4e0d\u8981\u7528time\u6a21\u5757 \u5c06UTC\u3001EST\u65f6\u533a\u7684\u65f6\u95f4\u8f6c\u5316\u6210\u5317\u4eac\u65f6\u95f4\uff08python\uff09 pytz\u5e93\u65f6\u533a\u7684\u5751\uff08\u8f6c\uff09 The Solution&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[10,3],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"San Francisco Time ?? Beijing Time ?? \u628a\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u6e7e\u533a9:00am\uff0c\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\uff0c\u5e94\u8be5\u662f\u5f88\u7b80\u5355\u7684\u95ee\u9898\u3002\u7528Python\u505a\u65f6\u533a\u8f6c\u6362\u597d\u50cf\u633a\u9ebb\u70e6\u7684\uff0c\u5bb9\u6613\u51fa\u9519\u3002Google\u51fa\u6765\u7684\u524d\u51e0\u6761\u7ed3\u679c\u90fd\u4e0d\u662f\u5f88\u8ba9\u4eba\u6ee1\u610f\uff0c\u672c\u6587\u603b\u7ed3\u6211\u6d4b\u8bd5\u8fc7\u53ef\u9760\u53ef\u884c\u4e0d\u592a\u590d\u6742\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5bb9\u6613\u51fa\u9519\u7684\u5730\u65b9\u3002 \u5148\u4e0a\u53ef\u884c\u7684Python\u4f8b\u5b50\uff0c\u628a\u4e09\u85e9\uff08SF\uff09\u6e7e\u533a\u65f6\u95f49am, \u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u5317\u4eac\u65f6\u95f4\uff0c\u7528\u4e86datetime\u548cpytz\u3002\u5148\u6784\u9020\u4e00\u4e2a\u6e7e\u533a\u65f6\u95f4\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u8f6c\u5316\u6210\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\u3002 \u52a0\u4e0a\u6ce8\u89e3\u548cdebug\u4fe1\u606f\u3002 \u53ef\u4ee5\u770b\u5230\u5efa\u7acb\u7684\u6e7e\u533a\u65f6\u95f4\u65f6\u533a\u4e3a-0700\u800c\u5317\u4eac\u65f6\u95f4\u4e3a0800\uff0c\u53ef\u4ee5\u9a8c\u8bc1\u6e7e\u533a\u548c\u4e2d\u56fd\u65f6\u5dee\u4e3a15\u5c0f\u65f6\u3002 \u65f6\u533a\u884c\u8bdd\u89e3\u91ca \u5168\u7403\u6807\u51c6\u65f6\u95f4\u7528\u7684\u662f\u4f4d\u4e8e\u82f1\u56fd\u7684\u683c\u6797\u5a01\u6cbb\u65f6\u95f4(GMT, Greenwich Mean Time)\u3002\u56e0\u4e3a\u4ee5\u524d\u683c\u6797\u5a01\u6cbb\u5929\u6587\u53f0\u662f\u4e16\u754c\u4e2d\u5fc3\uff0c\u672c\u521d\u5b50\u5348\u7ebf\u6216\u80050\u5ea6\u7ecf\u7ebf\u5c31\u5b9a\u4e49\u4e3a\u7a7f\u8fc7\u5b83\u7684\u7ecf\u7ebf\u3002\u7136\u540e\u53c8\u6709\u4e86\u4e00\u4e2a\u53eb\u4e16\u754c\u534f\u8c03\u65f6\u95f4\u7684\u4e1c\u897f\uff08UTC, Coordinated Universal Time\uff09\u3002\u8fd9\u4e2a\u548cGMT\u57fa\u672c\u4e00\u81f4\uff0c\u5927\u6982\u5c31\u662f\u5317\u4eac\u8bdd\u548c\u666e\u901a\u8bdd\u7684\u533a\u522b\u5427\u3002\u5317\u4eac\u5728Greenwich\u7684\u4e1c\u8fb9\uff0c\u65f6\u95f4\u9886\u5148GMT\/UTC 8\u5c0f\u65f6\uff0c\u6240\u4ee5\u53eb\u4e1c\u516b\u533a\uff0c\u4ee3\u53f70800\u3002\u800c\u6e7e\u533a\u5728\u683c\u6797\u5a01\u6cbb\u7684\u897f\u8fb9\uff0c\u65f6\u95f4\u6ede\u540e7\u4e2a\u5c0f\u65f6\uff08\u7f8e\u56fd\u56fd\u4f1a\u901a\u8fc7\u4e86\u6c38\u4e45\u4f7f\u7528\u590f\u4ee4\u65f6\u6cd5\u6848\uff09\uff0c\u6240\u4ee5\u53eb\u897f7\u533a\uff0c\u4ee3\u53f7-0700\u3002\u800c\u4e24\u5730\u65f6\u5dee\u4e3a7+9=15\uff0c\u5317\u4eac\u65f6\u95f4\u6bd4\u6e7e\u533a\u65f6\u95f4\u9886\u514815\u4e2a\u5c0f\u65f6\u3002 \u540c\u7406\uff0c\u65e5\u672c\u548c\u97e9\u56fd\u4f4d\u4e8e\u4e1c9\u533a\uff0c\u4ee3\u53f7\u4e3a0900\uff0c\u90a3\u4e48\u65f6\u95f4\u5c31\u6bd4\u4e3a\u4e0e\u4e1c\u516b\u533a\u7684\u4e2d\u56fd\u65e91\u5c0f\u65f6\u3002 \u5f53\u5730\u771f\u5b9e\u65f6\u95f4\u548c\u7ea6\u5b9a\u6807\u51c6\u65f6\u95f4 \u4e00\u4e2a\u5730\u65b9\u7684\u771f\u5b9e\u65f6\u95f4\u53ea\u53d6\u51b3\u4e8e\u592a\u9633\u76f8\u5bf9\u5f53\u5730\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u53d6\u51b3\u4e8e\u5f53\u5730\u7ecf\u5ea6\u3002\u4f46\u662f\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6bcf\u4e2a\u56fd\u5bb6\u53ef\u4ee5\u4eba\u4e3a\u89c4\u5b9a\u7528\u4ec0\u4e48\u65f6\u95f4\u3002\u6bd4\u5982\u6574\u4e2a\u4e2d\u56fd\u867d\u7136\u8de8\u4e86\u51e0\u4e2a\u7eac\u5ea6\uff0c\u786e\u4eba\u4e3a\u89c4\u5b9a\u4e86\u5404\u5730\u90fd\u4f7f\u7528\u5317\u4eac\u65f6\u95f4\u3002\u65b0\u52a0\u5761\u771f\u5b9e\u65f6\u95f4\u5e94\u8be5\u4e3a0655\uff0c\u786e\u89c4\u5b9a\u4f7f\u75280800\uff0c\u4e5f\u8bb8\u662f\u548c\u5927\u4e2d\u534e\u533a\u4fdd\u6301\u4e00\u81f4\u6bd4\u8f83\u65b9\u4fbf\u3002 \u56de\u5230Python\u4e0a\uff0c\u8fd9\u4e5f\u6b63\u662fpytz\u5305\u7684\u4e00\u4e9b\u5751\u7684\u6765\u6e90\u3002pytz\u7528\u7684\u662f\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\uff0c\u800c\u4eba\u4eec\u771f\u6b63\u4f7f\u7528\u7684\u662f\u5f53\u5730\u6cd5\u5f8b\u7ea6\u5b9a\u7684\u65f6\u95f4\uff0c\u8fd9\u4e24\u8005\u662f\u6709\u5dee\u522b\u7684\u3002 Python datetime\u4e0d\u8bbe\u65f6\u533a\u662f\u4ec0\u4e48\u65f6\u95f4\uff1f \u5982\u679c\u65b0\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61\uff0c\u4e0d\u8bbe\u65f6\u533a\u7684\u8bdd\uff0c\u4f1a\u662f\u5f53\u5730\u65f6\u95f4\u3002 \u7528epochconverter\u8f6c\u63621656658800.0\uff0c\u6b63\u662f\u6e7e\u533a\u65f6\u95f42022-07-01 00:00:00 \u5982\u679creplace\u4e86timezone\uff0c\u5c31\u628a\u5e95\u4e0b\u7684timestamp\u53d8\u4e86\uff0c\u800c\u4e0d\u662f\u4fdd\u6301timestamp\u800c\u6539\u53d8\u65f6\u95f4\u8868\u793a\u5f62\u5f0f\uff08\u65e5\u671f\uff0c\u5c0f\u65f6\/\u5206\/\u79d2\uff09\u3002\u6240\u4ee5replace(tzinfo=&#8230;)\u5e76\u4e0d\u662f\u505a\u65f6\u533a\u53d8\u6362\u3002\u800c\u4e14\u6ce8\u610f\u4e0b\u9762\u4f8b\u5b50\u91cc\u4e0a\u6d77\u65f6\u95f4\u662f0806\uff0c\u5e76\u4e0d\u662f0800\uff0c\u5e94\u8be5\u7528\u4e86\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\u800c\u4e0d\u662f\u6cd5\u5b9a\u65f6\u95f4\u3002\u8fd9\u4e2a\u5730\u7406\u65f6\u95f4\u5728\u751f\u6d3b\u4e2d\u57fa\u672c\u6ca1\u7528\uff0c\u8fd9\u4e2apytz\u7684\u5751\u4e4b\u4e00\u3002 \u53c2\u8003 Python3\u4e2ddatetime\u65f6\u533a\u8f6c\u6362\u4ecb\u7ecd\u4e0e\u8e29\u5751 python datetime\u65f6\u533a\u8f6c\u6362 \u6280\u5de7\uff1a\u7528datetime\u6a21\u5757\u5904\u7406\u65f6\u533a\u8f6c\u6362\uff0c\u4e0d\u8981\u7528time\u6a21\u5757 \u5c06UTC\u3001EST\u65f6\u533a\u7684\u65f6\u95f4\u8f6c\u5316\u6210\u5317\u4eac\u65f6\u95f4\uff08python\uff09 pytz\u5e93\u65f6\u533a\u7684\u5751\uff08\u8f6c\uff09 The Solution...Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-12T20:22:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-15T07:00:15+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2022\/07\/image-5.png\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50\",\"datePublished\":\"2022-07-12T20:22:26+00:00\",\"dateModified\":\"2022-07-15T07:00:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\"},\"wordCount\":112,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"articleSection\":[\"Python\",\"\u7f16\u7a0b\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\",\"name\":\"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2022-07-12T20:22:26+00:00\",\"dateModified\":\"2022-07-15T07:00:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant","og_locale":"en_US","og_type":"article","og_title":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning","og_description":"San Francisco Time ?? Beijing Time ?? \u628a\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u6e7e\u533a9:00am\uff0c\u8f6c\u6362\u6210\u53e6\u4e00\u4e2a\u65f6\u533a\u7684\u65f6\u95f4\uff0c\u6bd4\u5982\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\uff0c\u5e94\u8be5\u662f\u5f88\u7b80\u5355\u7684\u95ee\u9898\u3002\u7528Python\u505a\u65f6\u533a\u8f6c\u6362\u597d\u50cf\u633a\u9ebb\u70e6\u7684\uff0c\u5bb9\u6613\u51fa\u9519\u3002Google\u51fa\u6765\u7684\u524d\u51e0\u6761\u7ed3\u679c\u90fd\u4e0d\u662f\u5f88\u8ba9\u4eba\u6ee1\u610f\uff0c\u672c\u6587\u603b\u7ed3\u6211\u6d4b\u8bd5\u8fc7\u53ef\u9760\u53ef\u884c\u4e0d\u592a\u590d\u6742\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5bb9\u6613\u51fa\u9519\u7684\u5730\u65b9\u3002 \u5148\u4e0a\u53ef\u884c\u7684Python\u4f8b\u5b50\uff0c\u628a\u4e09\u85e9\uff08SF\uff09\u6e7e\u533a\u65f6\u95f49am, \u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u5317\u4eac\u65f6\u95f4\uff0c\u7528\u4e86datetime\u548cpytz\u3002\u5148\u6784\u9020\u4e00\u4e2a\u6e7e\u533a\u65f6\u95f4\u7684\u5bf9\u8c61\uff0c\u7136\u540e\u8f6c\u5316\u6210\u5317\u4eac\/\u9999\u6e2f\/\u65b0\u52a0\u5761\u65f6\u95f4\u3002 \u52a0\u4e0a\u6ce8\u89e3\u548cdebug\u4fe1\u606f\u3002 \u53ef\u4ee5\u770b\u5230\u5efa\u7acb\u7684\u6e7e\u533a\u65f6\u95f4\u65f6\u533a\u4e3a-0700\u800c\u5317\u4eac\u65f6\u95f4\u4e3a0800\uff0c\u53ef\u4ee5\u9a8c\u8bc1\u6e7e\u533a\u548c\u4e2d\u56fd\u65f6\u5dee\u4e3a15\u5c0f\u65f6\u3002 \u65f6\u533a\u884c\u8bdd\u89e3\u91ca \u5168\u7403\u6807\u51c6\u65f6\u95f4\u7528\u7684\u662f\u4f4d\u4e8e\u82f1\u56fd\u7684\u683c\u6797\u5a01\u6cbb\u65f6\u95f4(GMT, Greenwich Mean Time)\u3002\u56e0\u4e3a\u4ee5\u524d\u683c\u6797\u5a01\u6cbb\u5929\u6587\u53f0\u662f\u4e16\u754c\u4e2d\u5fc3\uff0c\u672c\u521d\u5b50\u5348\u7ebf\u6216\u80050\u5ea6\u7ecf\u7ebf\u5c31\u5b9a\u4e49\u4e3a\u7a7f\u8fc7\u5b83\u7684\u7ecf\u7ebf\u3002\u7136\u540e\u53c8\u6709\u4e86\u4e00\u4e2a\u53eb\u4e16\u754c\u534f\u8c03\u65f6\u95f4\u7684\u4e1c\u897f\uff08UTC, Coordinated Universal Time\uff09\u3002\u8fd9\u4e2a\u548cGMT\u57fa\u672c\u4e00\u81f4\uff0c\u5927\u6982\u5c31\u662f\u5317\u4eac\u8bdd\u548c\u666e\u901a\u8bdd\u7684\u533a\u522b\u5427\u3002\u5317\u4eac\u5728Greenwich\u7684\u4e1c\u8fb9\uff0c\u65f6\u95f4\u9886\u5148GMT\/UTC 8\u5c0f\u65f6\uff0c\u6240\u4ee5\u53eb\u4e1c\u516b\u533a\uff0c\u4ee3\u53f70800\u3002\u800c\u6e7e\u533a\u5728\u683c\u6797\u5a01\u6cbb\u7684\u897f\u8fb9\uff0c\u65f6\u95f4\u6ede\u540e7\u4e2a\u5c0f\u65f6\uff08\u7f8e\u56fd\u56fd\u4f1a\u901a\u8fc7\u4e86\u6c38\u4e45\u4f7f\u7528\u590f\u4ee4\u65f6\u6cd5\u6848\uff09\uff0c\u6240\u4ee5\u53eb\u897f7\u533a\uff0c\u4ee3\u53f7-0700\u3002\u800c\u4e24\u5730\u65f6\u5dee\u4e3a7+9=15\uff0c\u5317\u4eac\u65f6\u95f4\u6bd4\u6e7e\u533a\u65f6\u95f4\u9886\u514815\u4e2a\u5c0f\u65f6\u3002 \u540c\u7406\uff0c\u65e5\u672c\u548c\u97e9\u56fd\u4f4d\u4e8e\u4e1c9\u533a\uff0c\u4ee3\u53f7\u4e3a0900\uff0c\u90a3\u4e48\u65f6\u95f4\u5c31\u6bd4\u4e3a\u4e0e\u4e1c\u516b\u533a\u7684\u4e2d\u56fd\u65e91\u5c0f\u65f6\u3002 \u5f53\u5730\u771f\u5b9e\u65f6\u95f4\u548c\u7ea6\u5b9a\u6807\u51c6\u65f6\u95f4 \u4e00\u4e2a\u5730\u65b9\u7684\u771f\u5b9e\u65f6\u95f4\u53ea\u53d6\u51b3\u4e8e\u592a\u9633\u76f8\u5bf9\u5f53\u5730\u7684\u4f4d\u7f6e\uff0c\u4e5f\u5c31\u662f\u53d6\u51b3\u4e8e\u5f53\u5730\u7ecf\u5ea6\u3002\u4f46\u662f\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6bcf\u4e2a\u56fd\u5bb6\u53ef\u4ee5\u4eba\u4e3a\u89c4\u5b9a\u7528\u4ec0\u4e48\u65f6\u95f4\u3002\u6bd4\u5982\u6574\u4e2a\u4e2d\u56fd\u867d\u7136\u8de8\u4e86\u51e0\u4e2a\u7eac\u5ea6\uff0c\u786e\u4eba\u4e3a\u89c4\u5b9a\u4e86\u5404\u5730\u90fd\u4f7f\u7528\u5317\u4eac\u65f6\u95f4\u3002\u65b0\u52a0\u5761\u771f\u5b9e\u65f6\u95f4\u5e94\u8be5\u4e3a0655\uff0c\u786e\u89c4\u5b9a\u4f7f\u75280800\uff0c\u4e5f\u8bb8\u662f\u548c\u5927\u4e2d\u534e\u533a\u4fdd\u6301\u4e00\u81f4\u6bd4\u8f83\u65b9\u4fbf\u3002 \u56de\u5230Python\u4e0a\uff0c\u8fd9\u4e5f\u6b63\u662fpytz\u5305\u7684\u4e00\u4e9b\u5751\u7684\u6765\u6e90\u3002pytz\u7528\u7684\u662f\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\uff0c\u800c\u4eba\u4eec\u771f\u6b63\u4f7f\u7528\u7684\u662f\u5f53\u5730\u6cd5\u5f8b\u7ea6\u5b9a\u7684\u65f6\u95f4\uff0c\u8fd9\u4e24\u8005\u662f\u6709\u5dee\u522b\u7684\u3002 Python datetime\u4e0d\u8bbe\u65f6\u533a\u662f\u4ec0\u4e48\u65f6\u95f4\uff1f \u5982\u679c\u65b0\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61\uff0c\u4e0d\u8bbe\u65f6\u533a\u7684\u8bdd\uff0c\u4f1a\u662f\u5f53\u5730\u65f6\u95f4\u3002 \u7528epochconverter\u8f6c\u63621656658800.0\uff0c\u6b63\u662f\u6e7e\u533a\u65f6\u95f42022-07-01 00:00:00 \u5982\u679creplace\u4e86timezone\uff0c\u5c31\u628a\u5e95\u4e0b\u7684timestamp\u53d8\u4e86\uff0c\u800c\u4e0d\u662f\u4fdd\u6301timestamp\u800c\u6539\u53d8\u65f6\u95f4\u8868\u793a\u5f62\u5f0f\uff08\u65e5\u671f\uff0c\u5c0f\u65f6\/\u5206\/\u79d2\uff09\u3002\u6240\u4ee5replace(tzinfo=&#8230;)\u5e76\u4e0d\u662f\u505a\u65f6\u533a\u53d8\u6362\u3002\u800c\u4e14\u6ce8\u610f\u4e0b\u9762\u4f8b\u5b50\u91cc\u4e0a\u6d77\u65f6\u95f4\u662f0806\uff0c\u5e76\u4e0d\u662f0800\uff0c\u5e94\u8be5\u7528\u4e86\u5730\u7406\u610f\u4e49\u4e0a\u7684\u771f\u5b9e\u65f6\u95f4\u800c\u4e0d\u662f\u6cd5\u5b9a\u65f6\u95f4\u3002\u8fd9\u4e2a\u5730\u7406\u65f6\u95f4\u5728\u751f\u6d3b\u4e2d\u57fa\u672c\u6ca1\u7528\uff0c\u8fd9\u4e2apytz\u7684\u5751\u4e4b\u4e00\u3002 \u53c2\u8003 Python3\u4e2ddatetime\u65f6\u533a\u8f6c\u6362\u4ecb\u7ecd\u4e0e\u8e29\u5751 python datetime\u65f6\u533a\u8f6c\u6362 \u6280\u5de7\uff1a\u7528datetime\u6a21\u5757\u5904\u7406\u65f6\u533a\u8f6c\u6362\uff0c\u4e0d\u8981\u7528time\u6a21\u5757 \u5c06UTC\u3001EST\u65f6\u533a\u7684\u65f6\u95f4\u8f6c\u5316\u6210\u5317\u4eac\u65f6\u95f4\uff08python\uff09 pytz\u5e93\u65f6\u533a\u7684\u5751\uff08\u8f6c\uff09 The Solution...Read more","og_url":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant","og_site_name":"Feel Like Learning","article_published_time":"2022-07-12T20:22:26+00:00","article_modified_time":"2022-07-15T07:00:15+00:00","og_image":[{"url":"http:\/\/feellikelearning.com\/wp-content\/uploads\/2022\/07\/image-5.png"}],"author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50","datePublished":"2022-07-12T20:22:26+00:00","dateModified":"2022-07-15T07:00:15+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant"},"wordCount":112,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"articleSection":["Python","\u7f16\u7a0b"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant","url":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant","name":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50 | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2022-07-12T20:22:26+00:00","dateModified":"2022-07-15T07:00:15+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2022\/07\/12\/sf-bayarea-time-to-beijing-time-a-python-example-of-changing-time-zone\/?variant=zh-hant#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"\u65e7\u91d1\u5c71\u6e7e\u533a\u65f6\u95f4\u4e0e\u5317\u4eac\u65f6\u95f4\u8f6c\u6362\uff0c\u7528python\u5b9e\u73b0\u65f6\u533a\u8f6c\u6362\u4f8b\u5b50"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1472"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=1472"}],"version-history":[{"count":50,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1472\/revisions"}],"predecessor-version":[{"id":1588,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/1472\/revisions\/1588"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=1472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=1472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=1472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}