{"id":1061100,"date":"2024-12-31T15:39:57","date_gmt":"2024-12-31T07:39:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1061100.html"},"modified":"2024-12-31T15:39:59","modified_gmt":"2024-12-31T07:39:59","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%be%93%e5%87%ba%e5%bd%93%e5%89%8d%e6%97%b6%e9%97%b4%e5%92%8c%e6%97%a5%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1061100.html","title":{"rendered":"\u5982\u4f55\u7528python\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/e3a2b581-9b14-4ebd-8fa1-5a58b7e8c3b9.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u7528python\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\" \/><\/p>\n<p><p> <strong>\u7528Python\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528datetime\u6a21\u5757\u3001time\u6a21\u5757\u548cpytz\u6a21\u5757\u7b49\u3001\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f\u4f7f\u7528datetime\u6a21\u5757\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684datetime\u6a21\u5757\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u7c7b\u548c\u65b9\u6cd5\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u6570\u636e\u3002\u901a\u8fc7\u8fd9\u4e2a\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3001\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4\u3001\u4ee5\u53ca\u6267\u884c\u65e5\u671f\u548c\u65f6\u95f4\u7684\u7b97\u672f\u64cd\u4f5c\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528datetime\u6a21\u5757\u6765\u8f93\u51fa\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5e76\u8bf4\u660e\u5176\u4ed6\u4e00\u4e9b\u76f8\u5173\u7684\u65b9\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528datetime\u6a21\u5757\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f<\/h3>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165datetime\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4efb\u4f55\u64cd\u4f5c\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165datetime\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import datetime<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528datetime\u6a21\u5757\u4e2d\u7684<code>datetime.now()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">current_datetime = datetime.datetime.now()<\/p>\n<p>print(current_datetime)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code>2023-10-01 14:30:45.123456<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u683c\u5f0f\u5316\u8f93\u51fa<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u6211\u4eec\u9700\u8981\u4ee5\u7279\u5b9a\u7684\u683c\u5f0f\u8f93\u51fa\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u53ef\u4ee5\u4f7f\u7528<code>strftime<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">formatted_datetime = current_datetime.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)<\/p>\n<p>print(formatted_datetime)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code>2023-10-01 14:30:45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u66f4\u6539\u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>%Y<\/code>\uff1a\u56db\u4f4d\u6570\u7684\u5e74\u4efd<\/li>\n<li><code>%m<\/code>\uff1a\u4e24\u4f4d\u6570\u7684\u6708\u4efd\uff0801 \u5230 12\uff09<\/li>\n<li><code>%d<\/code>\uff1a\u4e24\u4f4d\u6570\u7684\u65e5\u671f\uff0801 \u5230 31\uff09<\/li>\n<li><code>%H<\/code>\uff1a\u4e24\u4f4d\u6570\u7684\u5c0f\u65f6\uff0800 \u5230 23\uff09<\/li>\n<li><code>%M<\/code>\uff1a\u4e24\u4f4d\u6570\u7684\u5206\u949f\uff0800 \u5230 59\uff09<\/li>\n<li><code>%S<\/code>\uff1a\u4e24\u4f4d\u6570\u7684\u79d2\uff0800 \u5230 59\uff09<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u4f7f\u7528time\u6a21\u5757\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f<\/h3>\n<\/p>\n<p><p>\u867d\u7136datetime\u6a21\u5757\u662f\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u7684\u9996\u9009\u6a21\u5757\uff0c\u4f46\u6709\u65f6\u4f7f\u7528time\u6a21\u5757\u4e5f\u662f\u4e00\u79cd\u9009\u62e9\u3002time\u6a21\u5757\u63d0\u4f9b\u4e86\u5904\u7406\u65f6\u95f4\u7684\u51fd\u6570\uff0c\u4e3b\u8981\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\u548c\u6267\u884c\u65f6\u95f4\u76f8\u5173\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u5165time\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165time\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>time.time()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\uff08\u81ea1970\u5e741\u67081\u65e5\u4ee5\u6765\u7684\u79d2\u6570\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">current_timestamp = time.time()<\/p>\n<p>print(current_timestamp)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u5f53\u524d\u65f6\u95f4\u6233\uff1a<\/p>\n<\/p>\n<p><pre><code>1633081845.123456<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u65f6\u95f4<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>time.localtime()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">struct_time = time.localtime(current_timestamp)<\/p>\n<p>print(struct_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u7ed3\u6784\u5316\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code>time.struct_time(tm_year=2023, tm_mon=10, tm_mday=1, tm_hour=14, tm_min=30, tm_sec=45, tm_wday=4, tm_yday=274, tm_isdst=0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u683c\u5f0f\u5316\u8f93\u51fa<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>time.strftime()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u683c\u5f0f\u5316\u8f93\u51fa\u7ed3\u6784\u5316\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">formatted_time = time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, struct_time)<\/p>\n<p>print(formatted_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code>2023-10-01 14:30:45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528pytz\u6a21\u5757\u5904\u7406\u65f6\u533a\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u65f6\uff0c\u65f6\u533a\u95ee\u9898\u662f\u4e0d\u53ef\u5ffd\u89c6\u7684\u3002pytz\u6a21\u5757\u63d0\u4f9b\u4e86\u5168\u4e16\u754c\u7684\u65f6\u533a\u4fe1\u606f\uff0c\u5141\u8bb8\u6211\u4eec\u8f7b\u677e\u5730\u5904\u7406\u65f6\u533a\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5pytz\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5pytz\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install pytz<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5bfc\u5165pytz\u548cdatetime\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5bfc\u5165pytz\u548cdatetime\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import datetime<\/p>\n<p>import pytz<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528pytz\u6a21\u5757\u53ef\u4ee5\u83b7\u53d6\u7279\u5b9a\u65f6\u533a\u7684\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">timezone = pytz.timezone(&quot;Asia\/Shangh<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>&quot;)<\/p>\n<p>current_datetime = datetime.datetime.now(timezone)<\/p>\n<p>print(current_datetime)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26\u65f6\u533a\u4fe1\u606f\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code>2023-10-01 14:30:45.123456+08:00<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u683c\u5f0f\u5316\u8f93\u51fa<\/h4>\n<\/p>\n<p><p>\u4e0edatetime\u6a21\u5757\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>strftime<\/code>\u65b9\u6cd5\u683c\u5f0f\u5316\u8f93\u51fa\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">formatted_datetime = current_datetime.strftime(&quot;%Y-%m-%d %H:%M:%S %Z%z&quot;)<\/p>\n<p>print(formatted_datetime)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u683c\u5f0f\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff08\u5e26\u65f6\u533a\u4fe1\u606f\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code>2023-10-01 14:30:45 CST+0800<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7efc\u5408\u793a\u4f8b\uff1a\u4f7f\u7528\u51fd\u6570\u5c01\u88c5<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u65b9\u4fbf\u5730\u83b7\u53d6\u548c\u683c\u5f0f\u5316\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\uff0c\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u64cd\u4f5c\u5c01\u88c5\u5728\u51fd\u6570\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import datetime<\/p>\n<p>import time<\/p>\n<p>import pytz<\/p>\n<p>def get_current_datetime():<\/p>\n<p>    return datetime.datetime.now()<\/p>\n<p>def get_current_timestamp():<\/p>\n<p>    return time.time()<\/p>\n<p>def get_current_datetime_with_timezone(timezone_str=&quot;UTC&quot;):<\/p>\n<p>    timezone = pytz.timezone(timezone_str)<\/p>\n<p>    return datetime.datetime.now(timezone)<\/p>\n<p>def format_datetime(dt, fmt=&quot;%Y-%m-%d %H:%M:%S&quot;):<\/p>\n<p>    return dt.strftime(fmt)<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>current_datetime = get_current_datetime()<\/p>\n<p>print(format_datetime(current_datetime))<\/p>\n<p>current_timestamp = get_current_timestamp()<\/p>\n<p>print(current_timestamp)<\/p>\n<p>current_datetime_with_timezone = get_current_datetime_with_timezone(&quot;Asia\/Shanghai&quot;)<\/p>\n<p>print(format_datetime(current_datetime_with_timezone, &quot;%Y-%m-%d %H:%M:%S %Z%z&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3001\u65f6\u95f4\u6233\uff0c\u4ee5\u53ca\u5e26\u65f6\u533a\u4fe1\u606f\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5e76\u8fdb\u884c\u4e86\u683c\u5f0f\u5316\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528datetime\u6a21\u5757\u3001time\u6a21\u5757\u548cpytz\u6a21\u5757\u7b49\u3002<\/strong> \u901a\u8fc7\u8fd9\u4e9b\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3001\u683c\u5f0f\u5316\u8f93\u51fa\u3001\u5904\u7406\u65f6\u533a\u95ee\u9898\u7b49\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4e86\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u638c\u63e1Python\u4e2d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6\u5f53\u524d\u7684\u65f6\u95f4\u548c\u65e5\u671f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>datetime<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u5f53\u524d\u7684\u65f6\u95f4\u548c\u65e5\u671f\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<pre><code class=\"language-python\">import datetime\n\ncurrent_datetime = datetime.datetime.now()\nprint(&quot;\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f:&quot;, current_datetime)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u8f93\u51fa\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u683c\u5f0f\u4e3a\u5e74-\u6708-\u65e5 \u65f6:\u5206:\u79d2\u3002<\/p>\n<p><strong>\u5982\u4f55\u683c\u5f0f\u5316\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\uff1f<\/strong><br \/>\u4f7f\u7528<code>strftime<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u65e5\u671f\u548c\u65f6\u95f4\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import datetime\n\ncurrent_datetime = datetime.datetime.now()\nformatted_datetime = current_datetime.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)\nprint(&quot;\u683c\u5f0f\u5316\u540e\u7684\u65f6\u95f4\u548c\u65e5\u671f:&quot;, formatted_datetime)\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>%Y<\/code>\u8868\u793a\u5e74\u4efd\uff0c<code>%m<\/code>\u8868\u793a\u6708\u4efd\uff0c<code>%d<\/code>\u8868\u793a\u65e5\u671f\uff0c<code>%H<\/code>\u8868\u793a\u5c0f\u65f6\uff0c<code>%M<\/code>\u8868\u793a\u5206\u949f\uff0c<code>%S<\/code>\u8868\u793a\u79d2\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6\u5f53\u524d\u7684UTC\u65f6\u95f4\uff1f<\/strong><br \/>\u83b7\u53d6\u5f53\u524d\u7684UTC\u65f6\u95f4\u540c\u6837\u53ef\u4ee5\u5229\u7528<code>datetime<\/code>\u6a21\u5757\uff0c\u4f7f\u7528<code>datetime.datetime.utcnow()<\/code>\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import datetime\n\ncurrent_utc_datetime = datetime.datetime.utcnow()\nprint(&quot;\u5f53\u524dUTC\u65f6\u95f4\u548c\u65e5\u671f:&quot;, current_utc_datetime)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u8f93\u51fa\u5f53\u524d\u7684UTC\u65f6\u95f4\u548c\u65e5\u671f\uff0c\u9002\u5408\u9700\u8981\u5904\u7406\u56fd\u9645\u65f6\u95f4\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u8f93\u51fa\u5f53\u524d\u65f6\u95f4\u548c\u65e5\u671f\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528datetime\u6a21\u5757\u3001time\u6a21\u5757\u548cpytz\u6a21\u5757\u7b49\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1061113,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1061100"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1061100"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1061100\/revisions"}],"predecessor-version":[{"id":1061116,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1061100\/revisions\/1061116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1061113"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1061100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1061100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1061100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}