{"id":1162741,"date":"2025-01-15T14:47:02","date_gmt":"2025-01-15T06:47:02","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1162741.html"},"modified":"2025-01-15T14:47:05","modified_gmt":"2025-01-15T06:47:05","slug":"python%e5%a6%82%e4%bd%95%e4%bc%a0%e5%85%a5%e6%97%b6%e9%97%b4%e5%8f%82%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1162741.html","title":{"rendered":"python\u5982\u4f55\u4f20\u5165\u65f6\u95f4\u53c2\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25203652\/70fa2aa8-037d-4031-89a5-43951876d071.webp\" alt=\"python\u5982\u4f55\u4f20\u5165\u65f6\u95f4\u53c2\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u5305\u62ec\uff1a\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u3001<code>datetime<\/code>\u5bf9\u8c61\u3001\u65f6\u95f4\u6233\u3001\u4ee5\u53ca\u65f6\u95f4\u5143\u7ec4\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528<code>datetime<\/code>\u5bf9\u8c61\u662f\u4e00\u79cd\u8f83\u4e3a\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u8fdb\u884c\u65f6\u95f4\u8fd0\u7b97\u548c\u683c\u5f0f\u5316\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>datetime<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u65f6\u95f4\u53c2\u6570\uff0c\u5e76\u4e3e\u4f8b\u8bf4\u660e\u5176\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528<code>datetime<\/code>\u5bf9\u8c61\u4f20\u5165\u65f6\u95f4\u53c2\u6570<\/strong><\/p>\n<\/p>\n<p><p><code>datetime<\/code>\u6a21\u5757\u662fPython\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u7684\u6807\u51c6\u6a21\u5757\u3002\u901a\u8fc7\u521b\u5efa<code>datetime<\/code>\u5bf9\u8c61\uff0c\u4f60\u53ef\u4ee5\u4f20\u9012\u5177\u4f53\u7684\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\uff0c\u5e76\u4e14\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u52a0\u51cf\u65f6\u95f4\u3001\u6bd4\u8f83\u65f6\u95f4\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528<code>datetime<\/code>\u5bf9\u8c61\u4f20\u5165\u65f6\u95f4\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>def print_time_info(input_time: datetime):<\/p>\n<p>    print(&quot;Year:&quot;, input_time.year)<\/p>\n<p>    print(&quot;Month:&quot;, input_time.month)<\/p>\n<p>    print(&quot;Day:&quot;, input_time.day)<\/p>\n<p>    print(&quot;Hour:&quot;, input_time.hour)<\/p>\n<p>    print(&quot;Minute:&quot;, input_time.minute)<\/p>\n<p>    print(&quot;Second:&quot;, input_time.second)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>current_time = datetime.now()<\/p>\n<p>print_time_info(current_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>datetime.now()<\/code>\u51fd\u6570\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9<code>print_time_info<\/code>\u51fd\u6570\u3002\u51fd\u6570\u5185\u90e8\u53ef\u4ee5\u8bbf\u95ee<code>datetime<\/code>\u5bf9\u8c61\u7684\u5404\u79cd\u5c5e\u6027\uff0c\u5982\u5e74\u3001\u6708\u3001\u65e5\u3001\u65f6\u3001\u5206\u3001\u79d2\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u66f4\u591a\u5173\u4e8e\u5982\u4f55\u5728Python\u4e2d\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u7684\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u4f20\u5165\u65f6\u95f4\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u683c\u5f0f\u662f\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u7684\u5e38\u7528\u65b9\u5f0f\u4e4b\u4e00\u3002\u901a\u5e38\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u7279\u5b9a\u7684\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\uff08\u5982<code>YYYY-MM-DD HH:MM:SS<\/code>\uff09\u6765\u8868\u793a\u65f6\u95f4\uff0c\u7136\u540e\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u89e3\u6790\u3002Python\u7684<code>strptime<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a<code>datetime<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>def process_time(time_str: str):<\/p>\n<p>    # \u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u4e3adatetime\u5bf9\u8c61<\/p>\n<p>    time_format = &quot;%Y-%m-%d %H:%M:%S&quot;<\/p>\n<p>    time_obj = datetime.strptime(time_str, time_format)<\/p>\n<p>    print(&quot;Parsed datetime:&quot;, time_obj)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u4f20\u5165\u65f6\u95f4\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>process_time(&quot;2023-10-01 12:30:45&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>process_time<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u65f6\u95f4\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4f7f\u7528<code>datetime.strptime<\/code>\u65b9\u6cd5\u5c06\u5176\u89e3\u6790\u4e3a<code>datetime<\/code>\u5bf9\u8c61\u3002\u65f6\u95f4\u683c\u5f0f<code>%Y-%m-%d %H:%M:%S<\/code>\u6307\u5b9a\u4e86\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\uff0c\u5176\u4e2d<code>%Y<\/code>\u8868\u793a\u56db\u4f4d\u6570\u5e74\u4efd\uff0c<code>%m<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u6708\u4efd\uff0c<code>%d<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u65e5\u671f\uff0c<code>%H<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u5c0f\u65f6\uff0c<code>%M<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u5206\u949f\uff0c<code>%S<\/code>\u8868\u793a\u4e24\u4f4d\u6570\u79d2\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u65f6\u95f4\u6233\u4f20\u5165\u65f6\u95f4\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u65f6\u95f4\u6233\uff08timestamp\uff09\u662f\u4e00\u4e2a\u4ee5\u79d2\u4e3a\u5355\u4f4d\u7684\u6d6e\u70b9\u6570\uff0c\u8868\u793a\u4ece1970\u5e741\u67081\u65e500:00:00 UTC\u5230\u67d0\u4e00\u65f6\u523b\u7684\u79d2\u6570\u3002\u65f6\u95f4\u6233\u53ef\u4ee5\u65b9\u4fbf\u5730\u8f6c\u6362\u4e3a<code>datetime<\/code>\u5bf9\u8c61\uff0c\u5e76\u7528\u4e8e\u65f6\u95f4\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>def timestamp_to_datetime(timestamp: float):<\/p>\n<p>    # \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61<\/p>\n<p>    time_obj = datetime.fromtimestamp(timestamp)<\/p>\n<p>    print(&quot;Converted datetime:&quot;, time_obj)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u4f20\u5165\u65f6\u95f4\u6233<\/strong><\/h2>\n<p>timestamp_to_datetime(1696152645.0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>timestamp_to_datetime<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u65f6\u95f4\u6233\uff08\u6d6e\u70b9\u6570\uff09\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4f7f\u7528<code>datetime.fromtimestamp<\/code>\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3a<code>datetime<\/code>\u5bf9\u8c61\u3002\u4f20\u5165\u7684\u65f6\u95f4\u6233<code>1696152645.0<\/code>\u8868\u793a\u4ece1970\u5e741\u67081\u65e500:00:00 UTC\u5f00\u59cb\u7684\u79d2\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u65f6\u95f4\u5143\u7ec4\u4f20\u5165\u65f6\u95f4\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u65f6\u95f4\u5143\u7ec4\uff08time tuple\uff09\u662f\u4e00\u79cd\u5305\u542b\u4e5d\u4e2a\u5143\u7d20\u7684\u5143\u7ec4\uff0c\u5206\u522b\u8868\u793a\u5e74\u3001\u6708\u3001\u65e5\u3001\u5c0f\u65f6\u3001\u5206\u949f\u3001\u79d2\u3001\u661f\u671f\u51e0\u3001\u5e74\u4efd\u4e2d\u7684\u7b2c\u51e0\u5929\u548c\u590f\u4ee4\u65f6\u6807\u5fd7\u3002Python\u7684<code>time<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5904\u7406\u65f6\u95f4\u5143\u7ec4\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def tuple_to_datetime(time_tuple: tuple):<\/p>\n<p>    # \u5c06\u65f6\u95f4\u5143\u7ec4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\uff0c\u518d\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61<\/p>\n<p>    timestamp = time.mktime(time_tuple)<\/p>\n<p>    time_obj = datetime.fromtimestamp(timestamp)<\/p>\n<p>    print(&quot;Converted datetime:&quot;, time_obj)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u4f20\u5165\u65f6\u95f4\u5143\u7ec4<\/strong><\/h2>\n<p>time_tuple = (2023, 10, 1, 12, 30, 45, 0, 274, -1)<\/p>\n<p>tuple_to_datetime(time_tuple)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>tuple_to_datetime<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u65f6\u95f4\u5143\u7ec4\u4f5c\u4e3a\u53c2\u6570\u3002\u65f6\u95f4\u5143\u7ec4<code>(2023, 10, 1, 12, 30, 45, 0, 274, -1)<\/code>\u8868\u793a2023\u5e7410\u67081\u65e512\u65f630\u520645\u79d2\u3002\u6211\u4eec\u4f7f\u7528<code>time.mktime<\/code>\u65b9\u6cd5\u5c06\u65f6\u95f4\u5143\u7ec4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\uff0c\u7136\u540e\u518d\u4f7f\u7528<code>datetime.fromtimestamp<\/code>\u65b9\u6cd5\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a<code>datetime<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5728\u51fd\u6570\u548c\u65b9\u6cd5\u4e2d\u4f7f\u7528\u65f6\u95f4\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5728\u51fd\u6570\u548c\u65b9\u6cd5\u4e2d\u4f20\u9012\u65f6\u95f4\u53c2\u6570\uff0c\u4ee5\u4fbf\u8fdb\u884c\u65f6\u95f4\u8fd0\u7b97\u3001\u65e5\u5fd7\u8bb0\u5f55\u3001\u6570\u636e\u5206\u6790\u7b49\u64cd\u4f5c\u3002\u4e0b\u9762\u4e3e\u4f8b\u8bf4\u660e\u5982\u4f55\u5728\u51fd\u6570\u548c\u65b9\u6cd5\u4e2d\u4f7f\u7528\u65f6\u95f4\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime, timedelta<\/p>\n<p>class EventScheduler:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.events = []<\/p>\n<p>    def schedule_event(self, event_time: datetime, event_name: str):<\/p>\n<p>        self.events.append((event_time, event_name))<\/p>\n<p>        print(f&quot;Event &#39;{event_name}&#39; scheduled for {event_time}&quot;)<\/p>\n<p>    def get_upcoming_events(self):<\/p>\n<p>        now = datetime.now()<\/p>\n<p>        upcoming_events = [event for event in self.events if event[0] &gt; now]<\/p>\n<p>        return upcoming_events<\/p>\n<h2><strong>\u521b\u5efa\u8c03\u5ea6\u5668\u5bf9\u8c61<\/strong><\/h2>\n<p>scheduler = EventScheduler()<\/p>\n<h2><strong>\u8c03\u7528\u65b9\u6cd5\uff0c\u4f20\u5165datetime\u5bf9\u8c61\u4f5c\u4e3a\u65f6\u95f4\u53c2\u6570<\/strong><\/h2>\n<p>event_time = datetime(2023, 10, 1, 12, 30, 45)<\/p>\n<p>scheduler.schedule_event(event_time, &quot;Meeting with team&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u5373\u5c06\u53d1\u751f\u7684\u4e8b\u4ef6<\/strong><\/h2>\n<p>upcoming_events = scheduler.get_upcoming_events()<\/p>\n<p>print(&quot;Upcoming events:&quot;, upcoming_events)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>EventScheduler<\/code>\u7684\u7c7b\uff0c\u8be5\u7c7b\u7528\u4e8e\u8c03\u5ea6\u548c\u7ba1\u7406\u4e8b\u4ef6\u3002\u7c7b\u4e2d\u5305\u542b\u4e00\u4e2a\u65b9\u6cd5<code>schedule_event<\/code>\uff0c\u8be5\u65b9\u6cd5\u63a5\u6536\u4e00\u4e2a<code>datetime<\/code>\u5bf9\u8c61\u548c\u4e00\u4e2a\u4e8b\u4ef6\u540d\u79f0\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u5c06\u4e8b\u4ef6\u6dfb\u52a0\u5230\u4e8b\u4ef6\u5217\u8868\u4e2d\u3002\u53e6\u4e00\u4e2a\u65b9\u6cd5<code>get_upcoming_events<\/code>\u7528\u4e8e\u83b7\u53d6\u5373\u5c06\u53d1\u751f\u7684\u4e8b\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u521b\u5efa<code>EventScheduler<\/code>\u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u8c03\u7528<code>schedule_event<\/code>\u65b9\u6cd5\u5e76\u4f20\u5165\u5177\u4f53\u7684<code>datetime<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u65f6\u95f4\u53c2\u6570\uff0c\u4ee5\u4fbf\u8c03\u5ea6\u4e8b\u4ef6\u3002<code>get_upcoming_events<\/code>\u65b9\u6cd5\u5219\u6839\u636e\u5f53\u524d\u65f6\u95f4\u7b5b\u9009\u51fa\u5373\u5c06\u53d1\u751f\u7684\u4e8b\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u65f6\u95f4\u53c2\u6570\u7684\u683c\u5f0f\u5316\u548c\u8f93\u51fa<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u65f6\u95f4\u53c2\u6570\u65f6\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5c06\u65f6\u95f4\u4ee5\u4e0d\u540c\u7684\u683c\u5f0f\u8f93\u51fa\uff0c\u4ee5\u4fbf\u4e8e\u9605\u8bfb\u548c\u8bb0\u5f55\u3002<code>datetime<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06<code>datetime<\/code>\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5404\u79cd\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>def format_time(input_time: datetime, format_str: str):<\/p>\n<p>    # \u5c06datetime\u5bf9\u8c61\u683c\u5f0f\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32<\/p>\n<p>    formatted_time = input_time.strftime(format_str)<\/p>\n<p>    print(&quot;Formatted time:&quot;, formatted_time)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>current_time = datetime.now()<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u4f20\u5165datetime\u5bf9\u8c61\u548c\u683c\u5f0f\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>format_time(current_time, &quot;%Y-%m-%d %H:%M:%S&quot;)<\/p>\n<p>format_time(current_time, &quot;%A, %B %d, %Y&quot;)<\/p>\n<p>format_time(current_time, &quot;%I:%M %p&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>format_time<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a<code>datetime<\/code>\u5bf9\u8c61\u548c\u4e00\u4e2a\u683c\u5f0f\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4f7f\u7528<code>strftime<\/code>\u65b9\u6cd5\u5c06<code>datetime<\/code>\u5bf9\u8c61\u683c\u5f0f\u5316\u4e3a\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002\u4e0d\u540c\u7684\u683c\u5f0f\u5b57\u7b26\u4e32\u53ef\u4ee5\u751f\u6210\u4e0d\u540c\u7684\u8f93\u51fa\u683c\u5f0f\uff0c\u5982<code>&quot;%Y-%m-%d %H:%M:%S&quot;<\/code>\u751f\u6210\u6807\u51c6\u7684\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\uff0c<code>&quot;%A, %B %d, %Y&quot;<\/code>\u751f\u6210\u5e26\u6709\u661f\u671f\u548c\u6708\u4efd\u540d\u79f0\u7684\u683c\u5f0f\uff0c<code>&quot;%I:%M %p&quot;<\/code>\u751f\u621012\u5c0f\u65f6\u5236\u65f6\u95f4\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u65f6\u95f4\u53c2\u6570\u7684\u52a0\u51cf\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>\u65f6\u95f4\u53c2\u6570\u7684\u52a0\u51cf\u8fd0\u7b97\u662f\u65f6\u95f4\u5904\u7406\u4e2d\u7684\u5e38\u89c1\u9700\u6c42\u3002<code>datetime<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86<code>timedelta<\/code>\u7c7b\uff0c\u7528\u4e8e\u8868\u793a\u65f6\u95f4\u95f4\u9694\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u52a0\u51cf\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime, timedelta<\/p>\n<p>def add_time(input_time: datetime, days: int, hours: int, minutes: int):<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u5bf9\u8c61<\/p>\n<p>    time_delta = timedelta(days=days, hours=hours, minutes=minutes)<\/p>\n<p>    # \u5c06\u65f6\u95f4\u95f4\u9694\u52a0\u5230\u8f93\u5165\u65f6\u95f4\u4e0a<\/p>\n<p>    new_time = input_time + time_delta<\/p>\n<p>    print(&quot;New time after addition:&quot;, new_time)<\/p>\n<p>def subtract_time(input_time: datetime, days: int, hours: int, minutes: int):<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u5bf9\u8c61<\/p>\n<p>    time_delta = timedelta(days=days, hours=hours, minutes=minutes)<\/p>\n<p>    # \u5c06\u65f6\u95f4\u95f4\u9694\u4ece\u8f93\u5165\u65f6\u95f4\u4e2d\u51cf\u53bb<\/p>\n<p>    new_time = input_time - time_delta<\/p>\n<p>    print(&quot;New time after subtraction:&quot;, new_time)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>current_time = datetime.now()<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u8fdb\u884c\u65f6\u95f4\u52a0\u51cf\u8fd0\u7b97<\/strong><\/h2>\n<p>add_time(current_time, 2, 3, 30)<\/p>\n<p>subtract_time(current_time, 1, 0, 0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e24\u4e2a\u51fd\u6570<code>add_time<\/code>\u548c<code>subtract_time<\/code>\uff0c\u5206\u522b\u7528\u4e8e\u8fdb\u884c\u65f6\u95f4\u7684\u52a0\u6cd5\u548c\u51cf\u6cd5\u8fd0\u7b97\u3002<code>timedelta<\/code>\u7c7b\u7528\u4e8e\u8868\u793a\u65f6\u95f4\u95f4\u9694\uff0c\u53ef\u4ee5\u6307\u5b9a\u5929\u3001\u5c0f\u65f6\u3001\u5206\u949f\u7b49\u53c2\u6570\u3002\u901a\u8fc7\u521b\u5efa<code>timedelta<\/code>\u5bf9\u8c61\u5e76\u8fdb\u884c\u52a0\u6cd5\u6216\u51cf\u6cd5\u8fd0\u7b97\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u65b0\u7684\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u65f6\u95f4\u53c2\u6570\u7684\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u65f6\u95f4\u53c2\u6570\u7684\u6bd4\u8f83\u662f\u5224\u65ad\u65f6\u95f4\u5148\u540e\u987a\u5e8f\u7684\u57fa\u672c\u64cd\u4f5c\u3002<code>datetime<\/code>\u5bf9\u8c61\u652f\u6301\u6bd4\u8f83\u64cd\u4f5c\u7b26\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from datetime import datetime<\/p>\n<p>def compare_times(time1: datetime, time2: datetime):<\/p>\n<p>    if time1 &gt; time2:<\/p>\n<p>        print(f&quot;{time1} is after {time2}&quot;)<\/p>\n<p>    elif time1 &lt; time2:<\/p>\n<p>        print(f&quot;{time1} is before {time2}&quot;)<\/p>\n<p>    else:<\/p>\n<p>        print(f&quot;{time1} is equal to {time2}&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u4e24\u4e2adatetime\u5bf9\u8c61<\/strong><\/h2>\n<p>time1 = datetime(2023, 10, 1, 12, 30, 45)<\/p>\n<p>time2 = datetime(2023, 10, 1, 15, 45, 30)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u6bd4\u8f83\u65f6\u95f4<\/strong><\/h2>\n<p>compare_times(time1, time2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>compare_times<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e24\u4e2a<code>datetime<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4f7f\u7528\u6bd4\u8f83\u64cd\u4f5c\u7b26<code>&gt;<\/code>\u3001<code>&lt;<\/code>\u548c<code>==<\/code>\u8fdb\u884c\u6bd4\u8f83\u3002\u6839\u636e\u6bd4\u8f83\u7ed3\u679c\uff0c\u51fd\u6570\u8f93\u51fa\u65f6\u95f4\u7684\u5148\u540e\u987a\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u65f6\u95f4\u53c2\u6570\u5728\u65e5\u5fd7\u8bb0\u5f55\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u7a0b\u5e8f\u65f6\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u91cd\u8981\u7684\u8c03\u8bd5\u548c\u76d1\u63a7\u624b\u6bb5\u3002\u901a\u8fc7\u8bb0\u5f55\u65f6\u95f4\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u4e86\u89e3\u7a0b\u5e8f\u7684\u8fd0\u884c\u65f6\u5e8f\u548c\u4e8b\u4ef6\u53d1\u751f\u7684\u5177\u4f53\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>from datetime import datetime<\/p>\n<h2><strong>\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u683c\u5f0f<\/strong><\/h2>\n<p>logging.basicConfig(level=logging.INFO, format=&#39;%(asctime)s - %(levelname)s - %(message)s&#39;)<\/p>\n<p>def log_event(event_name: str):<\/p>\n<p>    # \u83b7\u53d6\u5f53\u524d\u65f6\u95f4<\/p>\n<p>    event_time = datetime.now()<\/p>\n<p>    # \u8bb0\u5f55\u65e5\u5fd7<\/p>\n<p>    logging.info(f&quot;Event &#39;{event_name}&#39; occurred at {event_time}&quot;)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u8bb0\u5f55\u4e8b\u4ef6\u65e5\u5fd7<\/strong><\/h2>\n<p>log_event(&quot;Program started&quot;)<\/p>\n<p>log_event(&quot;User logged in&quot;)<\/p>\n<p>log_event(&quot;Data processing completed&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>logging<\/code>\u6a21\u5757\u8bb0\u5f55\u65e5\u5fd7\uff0c\u5e76\u914d\u7f6e\u65e5\u5fd7\u683c\u5f0f\u4e3a\u5305\u542b\u65f6\u95f4\u6233\u3002<code>log_event<\/code>\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u4e8b\u4ef6\u540d\u79f0\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u8bb0\u5f55\u65e5\u5fd7\u3002\u901a\u8fc7\u8c03\u7528<code>log_event<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8bb0\u5f55\u5404\u79cd\u4e8b\u4ef6\u7684\u53d1\u751f\u65f6\u95f4\uff0c\u4ee5\u4fbf\u4e8e\u8c03\u8bd5\u548c\u76d1\u63a7\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u65f6\u95f4\u53c2\u6570\u5728\u6570\u636e\u5206\u6790\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u65f6\u95f4\u53c2\u6570\u5e38\u7528\u4e8e\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u3001\u8d8b\u52bf\u9884\u6d4b\u3001\u6570\u636e\u5206\u7ec4\u7b49\u64cd\u4f5c\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u65f6\u95f4\u5e8f\u5217\u5904\u7406\u529f\u80fd\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u65f6\u95f4\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>def analyze_time_series(data: pd.DataFrame):<\/p>\n<p>    # \u5c06\u65e5\u671f\u5217\u8f6c\u6362\u4e3adatetime\u5bf9\u8c61<\/p>\n<p>    data[&#39;date&#39;] = pd.to_datetime(data[&#39;date&#39;])<\/p>\n<p>    # \u8bbe\u7f6e\u65e5\u671f\u5217\u4e3a\u7d22\u5f15<\/p>\n<p>    data.set_index(&#39;date&#39;, inplace=True)<\/p>\n<p>    # \u8ba1\u7b97\u6309\u6708\u7684\u5e73\u5747\u503c<\/p>\n<p>    monthly_avg = data.resample(&#39;M&#39;).mean()<\/p>\n<p>    print(&quot;Monthly average values:\\n&quot;, monthly_avg)<\/p>\n<h2><strong>\u521b\u5efa\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>data = pd.DataFrame({<\/p>\n<p>    &#39;date&#39;: [&#39;2023-10-01&#39;, &#39;2023-10-05&#39;, &#39;2023-11-10&#39;, &#39;2023-11-15&#39;],<\/p>\n<p>    &#39;value&#39;: [10, 15, 20, 25]<\/p>\n<p>})<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\uff0c\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u5206\u6790<\/strong><\/h2>\n<p>analyze_time_series(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pandas<\/code>\u5e93\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u3002\u9996\u5148\uff0c\u5c06\u65e5\u671f\u5217\u8f6c\u6362\u4e3a<code>datetime<\/code>\u5bf9\u8c61\uff0c\u5e76\u8bbe\u7f6e\u4e3a\u7d22\u5f15\u3002\u7136\u540e\uff0c\u4f7f\u7528<code>resample<\/code>\u65b9\u6cd5\u6309\u6708\u91cd\u91c7\u6837\u5e76\u8ba1\u7b97\u5e73\u5747\u503c\u3002\u901a\u8fc7\u8c03\u7528<code>analyze_time_series<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u5206\u6790\uff0c\u8ba1\u7b97\u6309\u6708\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u65f6\u95f4\u53c2\u6570\u5728\u5b9a\u65f6\u4efb\u52a1\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5b9a\u65f6\u4efb\u52a1\u662f\u5e38\u89c1\u9700\u6c42\uff0c\u4f8b\u5982\u5b9a\u65f6\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u3001\u5b9a\u65f6\u5907\u4efd\u6570\u636e\u7b49\u3002Python\u7684<code>schedule<\/code>\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import schedule<\/p>\n<p>import time<\/p>\n<p>from datetime import datetime<\/p>\n<p>def job():<\/p>\n<p>    print(f&quot;Task executed at {datetime.now()}&quot;)<\/p>\n<h2><strong>\u5b89\u6392\u4efb\u52a1\u6bcf\u592912:00\u6267\u884c<\/strong><\/h2>\n<p>schedule.every().day.at(&quot;12:00&quot;).do(job)<\/p>\n<h2><strong>\u8fd0\u884c\u4efb\u52a1\u8c03\u5ea6<\/strong><\/h2>\n<p>while True:<\/p>\n<p>    schedule.run_pending()<\/p>\n<p>    time.sleep(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>schedule<\/code>\u5e93\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u3002\u5b9a\u4e49\u4e00\u4e2a\u4efb\u52a1\u51fd\u6570<code>job<\/code>\uff0c\u7528\u4e8e\u6253\u5370\u6267\u884c\u65f6\u95f4\u3002\u4f7f\u7528<code>schedule.every().day.at(&quot;12:00&quot;).do(job)<\/code>\u5b89\u6392\u4efb\u52a1\u6bcf\u592912:00\u6267\u884c\u3002\u901a\u8fc7<code>while<\/code>\u5faa\u73af\u8fd0\u884c\u4efb\u52a1\u8c03\u5ea6\uff0c\u5b9a\u65f6\u68c0\u67e5\u5e76\u6267\u884c\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u5305\u62ec\uff1a\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u3001<code>datetime<\/code>\u5bf9\u8c61\u3001\u65f6\u95f4\u6233\u3001\u4ee5\u53ca\u65f6\u95f4\u5143\u7ec4\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c<code>datetime<\/code>\u5bf9\u8c61\u662f\u4e00\u79cd\u8f83\u4e3a\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u8fdb\u884c\u65f6\u95f4\u8fd0\u7b97\u548c\u683c\u5f0f\u5316\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u4f60\u53ef\u4ee5\u4e86\u89e3\u5982\u4f55\u5728Python\u4e2d\u4f20\u5165\u65f6\u95f4\u53c2\u6570\uff0c\u5e76\u638c\u63e1\u4f7f\u7528\u65f6\u95f4\u53c2\u6570\u8fdb\u884c\u683c\u5f0f\u5316\u3001\u8fd0\u7b97\u3001\u6bd4\u8f83\u3001\u65e5\u5fd7\u8bb0\u5f55\u3001\u6570\u636e\u5206\u6790\u548c\u5b9a\u65f6\u4efb\u52a1\u7b49\u64cd\u4f5c\u7684\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u65f6\u95f4\u53c2\u6570\u7684\u4f20\u5165\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\u6765\u5904\u7406\u65f6\u95f4\u53c2\u6570\uff0c\u4f8b\u5982<code>datetime<\/code>\u548c<code>time<\/code>\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u3001\u683c\u5f0f\u5316\u548c\u89e3\u6790\u65f6\u95f4\u5bf9\u8c61\u3002\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u65f6\uff0c\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3a\u5b57\u7b26\u4e32\u3001datetime\u5bf9\u8c61\u6216\u65f6\u95f4\u6233\u7b49\u5f62\u5f0f\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u51e0\u79cd\u5e38\u7528\u7684\u65f6\u95f4\u683c\u5f0f\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u65f6\u95f4\u683c\u5f0f\u5305\u62ecISO 8601\u683c\u5f0f\uff08\u4f8b\u5982\u201c2023-10-01T12:30:00\u201d\uff09\u3001Unix\u65f6\u95f4\u6233\uff08\u81ea1970\u5e741\u67081\u65e5\u8d77\u7684\u79d2\u6570\uff09\u3001\u4ee5\u53ca\u81ea\u5b9a\u4e49\u683c\u5f0f\uff08\u5982\u201c%Y-%m-%d %H:%M:%S\u201d\uff09\u3002\u4f7f\u7528<code>strptime()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a<code>datetime<\/code>\u5bf9\u8c61\uff0c\u800c<code>strftime()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06<code>datetime<\/code>\u5bf9\u8c61\u683c\u5f0f\u5316\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u51fd\u6570\u4e2d\u63a5\u6536\u5e76\u4f7f\u7528\u65f6\u95f4\u53c2\u6570\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\u8bbe\u7f6e\u65f6\u95f4\u53c2\u6570\uff0c\u4f8b\u5982\u4f7f\u7528<code>datetime<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\u7c7b\u578b\u3002\u5728\u51fd\u6570\u5185\u90e8\uff0c\u53ef\u4ee5\u5bf9\u4f20\u5165\u7684\u65f6\u95f4\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u5982\u6bd4\u8f83\u3001\u52a0\u51cf\u65f6\u95f4\u7b49\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>timedelta<\/code>\u5bf9\u8c61\u6765\u589e\u52a0\u6216\u51cf\u5c11\u65f6\u95f4\uff0c\u65b9\u4fbf\u8fdb\u884c\u65f6\u95f4\u8ba1\u7b97\u548c\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f20\u5165\u65f6\u95f4\u53c2\u6570\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u5305\u62ec\uff1a\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u3001datetime\u5bf9\u8c61\u3001\u65f6\u95f4\u6233\u3001\u4ee5\u53ca\u65f6\u95f4\u5143 [&hellip;]","protected":false},"author":3,"featured_media":1162747,"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\/1162741"}],"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=1162741"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1162741\/revisions"}],"predecessor-version":[{"id":1162749,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1162741\/revisions\/1162749"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1162747"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1162741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1162741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1162741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}