{"id":1122102,"date":"2025-01-08T19:16:57","date_gmt":"2025-01-08T11:16:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1122102.html"},"modified":"2025-01-08T19:16:59","modified_gmt":"2025-01-08T11:16:59","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e4%b8%ad%e6%89%93%e5%8d%b0%e5%bd%93%e5%89%8d%e6%97%a5%e6%9c%9f%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1122102.html","title":{"rendered":"\u5982\u4f55\u5728python\u4e2d\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084103\/eabf4728-bf08-4cb9-bb70-f71b924c2044.webp\" alt=\"\u5982\u4f55\u5728python\u4e2d\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u6700\u5e38\u7528\u7684\u662f\u4f7f\u7528datetime\u6a21\u5757\u3001time\u6a21\u5757\u3001\u4ee5\u53capytz\u6a21\u5757\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u70b9\uff0c\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/strong> \u4f7f\u7528datetime\u6a21\u5757\u662f\u6700\u5e38\u89c1\u548c\u76f4\u89c2\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528datetime\u6a21\u5757\u6765\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time = datetime.now()<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Current Date and Time: &quot;, current_date_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u7247\u6bb5\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528datetime\u6a21\u5757\u83b7\u53d6\u548c\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u5176\u4ed6\u65b9\u6cd5\u548c\u66f4\u591a\u9ad8\u7ea7\u7528\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u4f7f\u7528 datetime \u6a21\u5757<\/strong><\/h2>\n<p><p>datetime\u6a21\u5757\u662fPython\u5185\u7f6e\u6a21\u5757\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5904\u7406\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h2>1. \u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528datetime\u6a21\u5757\u7684<code>datetime.now()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time = datetime.now()<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Current Date and Time: &quot;, current_date_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\u7684<code>datetime.now()<\/code>\u65b9\u6cd5\u8fd4\u56de\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u5305\u542b\u5e74\u3001\u6708\u3001\u65e5\u3001\u65f6\u3001\u5206\u3001\u79d2\u548c\u5fae\u79d2\u3002<\/p>\n<\/p>\n<p><h2>2. \u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4<\/h2>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u4ee5\u7279\u5b9a\u7684\u683c\u5f0f\u6765\u8f93\u51fa\u65e5\u671f\u548c\u65f6\u95f4\u3002\u53ef\u4ee5\u4f7f\u7528<code>strftime<\/code>\u65b9\u6cd5\u6765\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time = datetime.now()<\/p>\n<h2><strong>\u683c\u5f0f\u5316\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>formatted_date_time = current_date_time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)<\/p>\n<h2><strong>\u6253\u5370\u683c\u5f0f\u5316\u540e\u7684\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Formatted Date and Time: &quot;, formatted_date_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u91cc\uff0c<code>strftime<\/code>\u65b9\u6cd5\u7528\u4e8e\u683c\u5f0f\u5316\u65e5\u671f\u65f6\u95f4\uff0c<code>%Y<\/code>\u8868\u793a\u56db\u4f4d\u6570\u7684\u5e74\u4efd\uff0c<code>%m<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u7684\u6708\u4efd\uff0c<code>%d<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u7684\u65e5\u671f\uff0c<code>%H<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u7684\u5c0f\u65f6\uff0824\u5c0f\u65f6\u5236\uff09\uff0c<code>%M<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u7684\u5206\u949f\uff0c<code>%S<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u7684\u79d2\u3002<\/p>\n<\/p>\n<p><h2>3. \u83b7\u53d6\u5f53\u524d\u65e5\u671f<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u53ea\u9700\u8981\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>date<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f<\/strong><\/h2>\n<p>current_date = datetime.now().date()<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524d\u65e5\u671f<\/strong><\/h2>\n<p>print(&quot;Current Date: &quot;, current_date)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e8c\u3001\u4f7f\u7528 time \u6a21\u5757<\/strong><\/h2>\n<p><p>time\u6a21\u5757\u662f\u53e6\u4e00\u4e2a\u5904\u7406\u65f6\u95f4\u7684\u6a21\u5757\uff0c\u9002\u5408\u9700\u8981\u65f6\u95f4\u6233\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h2>1. \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528time\u6a21\u5757\u7684<code>time()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u65f6\u95f4\u6233\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>current_timestamp = time.time()<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524d\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>print(&quot;Current Timestamp: &quot;, current_timestamp)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2. \u83b7\u53d6\u5f53\u524d\u65f6\u95f4<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528time\u6a21\u5757\u7684<code>localtime()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7684\u672c\u5730\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u672c\u5730\u65f6\u95f4<\/strong><\/h2>\n<p>local_time = time.localtime()<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524d\u672c\u5730\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Local Time: &quot;, time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, local_time))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e09\u3001\u4f7f\u7528 pytz \u6a21\u5757<\/strong><\/h2>\n<p><p>pytz\u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u65f6\u533a\u652f\u6301\u3002<\/p>\n<\/p>\n<p><h2>1. \u5b89\u88c5 pytz \u6a21\u5757<\/h2>\n<\/p>\n<p><p>\u9996\u5148\u9700\u8981\u5b89\u88c5pytz\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pytz<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2. \u83b7\u53d6\u5e26\u65f6\u533a\u7684\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528pytz\u6a21\u5757\u53ef\u4ee5\u83b7\u53d6\u5e26\u6709\u65f6\u533a\u4fe1\u606f\u7684\u5f53\u524d\u65e5\u671f\u65f6\u95f4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>import pytz<\/p>\n<h2><strong>\u83b7\u53d6\u5e26\u65f6\u533a\u7684\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time_tz = datetime.now(pytz.timezone(&#39;Asia\/Shangh<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>&#39;))<\/p>\n<h2><strong>\u6253\u5370\u5e26\u65f6\u533a\u7684\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Current Date and Time with Timezone: &quot;, current_date_time_tz)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pytz.timezone<\/code>\u65b9\u6cd5\u6307\u5b9a\u4e86\u65f6\u533a\u4e3a\u201cAsia\/Shanghai\u201d\uff0c\u7136\u540e\u4f7f\u7528<code>datetime.now()<\/code>\u65b9\u6cd5\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u7efc\u5408\u5e94\u7528<\/strong><\/h2>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u4ee5\u4e0a\u65b9\u6cd5\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7efc\u5408\u5e94\u7528\u7684\u4f8b\u5b50\u3002<\/p>\n<\/p>\n<p><h2>1. \u83b7\u53d6UTC\u65f6\u95f4<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime, timezone<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524dUTC\u65f6\u95f4<\/strong><\/h2>\n<p>utc_time = datetime.now(timezone.utc)<\/p>\n<h2><strong>\u6253\u5370\u5f53\u524dUTC\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Current UTC Time: &quot;, utc_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2. \u8f6c\u6362\u65f6\u95f4\u683c\u5f0f<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u539f\u59cb\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>date_time_str = &#39;2023-10-01 14:30:00&#39;<\/p>\n<h2><strong>\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>date_time_obj = datetime.strptime(date_time_str, &#39;%Y-%m-%d %H:%M:%S&#39;)<\/p>\n<h2><strong>\u6253\u5370datetime\u5bf9\u8c61<\/strong><\/h2>\n<p>print(&quot;Datetime Object: &quot;, date_time_obj)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3. \u8ba1\u7b97\u65f6\u95f4\u5dee<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime, timedelta<\/p>\n<h2><strong>\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>now = datetime.now()<\/p>\n<h2><strong>\u8ba1\u7b9730\u5929\u540e\u7684\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>future_date_time = now + timedelta(days=30)<\/p>\n<h2><strong>\u6253\u537030\u5929\u540e\u7684\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>print(&quot;Date and Time after 30 Days: &quot;, future_date_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e94\u3001\u5904\u7406\u65e5\u671f\u65f6\u95f4\u7684\u5b9e\u7528\u6280\u5de7<\/strong><\/h2>\n<p><h2>1. \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u5404\u4e2a\u90e8\u5206<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time = datetime.now()<\/p>\n<h2><strong>\u83b7\u53d6\u5e74\u3001\u6708\u3001\u65e5\u3001\u65f6\u3001\u5206\u3001\u79d2<\/strong><\/h2>\n<p>year = current_date_time.year<\/p>\n<p>month = current_date_time.month<\/p>\n<p>day = current_date_time.day<\/p>\n<p>hour = current_date_time.hour<\/p>\n<p>minute = current_date_time.minute<\/p>\n<p>second = current_date_time.second<\/p>\n<h2><strong>\u6253\u5370\u5404\u4e2a\u90e8\u5206<\/strong><\/h2>\n<p>print(f&quot;Year: {year}, Month: {month}, Day: {day}, Hour: {hour}, Minute: {minute}, Second: {second}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2. \u83b7\u53d6\u65f6\u95f4\u6233<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4<\/strong><\/h2>\n<p>current_date_time = datetime.now()<\/p>\n<h2><strong>\u83b7\u53d6\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>timestamp = current_date_time.timestamp()<\/p>\n<h2><strong>\u6253\u5370\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>print(&quot;Timestamp: &quot;, timestamp)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3. \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4<\/h2>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<h2><strong>\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>timestamp = 1696196700.0<\/p>\n<h2><strong>\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>date_time = datetime.fromtimestamp(timestamp)<\/p>\n<h2><strong>\u6253\u5370datetime\u5bf9\u8c61<\/strong><\/h2>\n<p>print(&quot;Datetime from Timestamp: &quot;, date_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516d\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5728Python\u4e2d\uff0c\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<strong>datetime\u6a21\u5757<\/strong>\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5904\u7406\u529f\u80fd\uff0c<strong>time\u6a21\u5757<\/strong>\u9002\u5408\u9700\u8981\u65f6\u95f4\u6233\u7684\u573a\u666f\uff0c<strong>pytz\u6a21\u5757<\/strong>\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u65f6\u533a\u652f\u6301\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u6a21\u5757\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u548c\u64cd\u4f5c\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u683c\u5f0f\u5316\u8f93\u51fa\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>datetime<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002\u901a\u8fc7<code>strftime<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u65e5\u671f\u65f6\u95f4\u5bf9\u8c61\u683c\u5f0f\u5316\u4e3a\u66f4\u6613\u8bfb\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>datetime.now().strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)<\/code>\u53ef\u4ee5\u8f93\u51fa\u7c7b\u4f3c\u4e8e\u201c2023-10-05 14:30:00\u201d\u7684\u683c\u5f0f\u3002\u8fd9\u79cd\u683c\u5f0f\u6e05\u6670\u4e14\u5e38\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\uff1f<\/strong><br \/>\u9664\u4e86<code>datetime<\/code>\u6a21\u5757\u5916\uff0cPython\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>time<\/code>\u6a21\u5757\u83b7\u53d6\u5f53\u524d\u7684\u65f6\u95f4\u6233\u3002\u4f7f\u7528<code>time.time()<\/code>\u53ef\u4ee5\u5f97\u5230\u81ea1970\u5e741\u67081\u65e5\u4ee5\u6765\u7684\u79d2\u6570\u3002\u5982\u679c\u60f3\u8981\u66f4\u6613\u8bfb\u7684\u683c\u5f0f\uff0c\u53ef\u4ee5\u7ed3\u5408<code>time.localtime()<\/code>\u548c<code>time.strftime()<\/code>\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c<code>time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.localtime())<\/code>\u540c\u6837\u80fd\u8f93\u51fa\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u663e\u793a\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u65f6\u533a\u4fe1\u606f\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u663e\u793a\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u65f6\u533a\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pytz<\/code>\u5e93\u4e0e<code>datetime<\/code>\u6a21\u5757\u7ed3\u5408\u4f7f\u7528\u3002\u9996\u5148\uff0c\u5b89\u88c5<code>pytz<\/code>\u5e93\uff0c\u7136\u540e\u4f7f\u7528<code>datetime.datetime.now(pytz.timezone(&#39;Asia\/Shanghai&#39;))<\/code>\u83b7\u53d6\u7279\u5b9a\u65f6\u533a\u7684\u5f53\u524d\u65f6\u95f4\u3002\u8fd9\u79cd\u65b9\u5f0f\u80fd\u591f\u786e\u4fdd\u65f6\u95f4\u7684\u51c6\u786e\u6027\uff0c\u5e76\u53ef\u4ee5\u5904\u7406\u590f\u4ee4\u65f6\u7b49\u60c5\u51b5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6253\u5370\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u6700\u5e38\u7528\u7684\u662f\u4f7f\u7528datetime\u6a21\u5757\u3001time\u6a21\u5757\u3001\u4ee5\u53capytz\u6a21 [&hellip;]","protected":false},"author":3,"featured_media":1122107,"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\/1122102"}],"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=1122102"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122102\/revisions"}],"predecessor-version":[{"id":1122108,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122102\/revisions\/1122108"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1122107"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1122102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1122102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1122102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}