{"id":87523,"date":"2024-01-26T05:51:14","date_gmt":"2024-01-25T21:51:14","guid":{"rendered":"http:\/\/gulass.cn\/?p=87523"},"modified":"2024-01-26T05:51:14","modified_gmt":"2024-01-25T21:51:14","slug":"python-time-submit","status":"publish","type":"post","link":"https:\/\/gulass.cn\/python-time-submit.html","title":{"rendered":"\u65f6\u95f4\u5904\u7406\u5927\u603b\u7ed3\u4e4bPython"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | python\u4e2d\u5904\u7406\u65f6\u95f4\u7684\u6a21\u5757\u6709\u4e09\u4e2a\uff0cdatetime, time,calendar\uff0c\u878d\u6c47\u8d2f\u901a\u4e09\u4e2a\u6a21\u5757\uff0c\u624d\u80fd\u968f\u5fc3\u6240\u6b32\u5730\u7528python\u5904\u7406\u65f6\u95f4\u3002\u672c\u6587\u5c31\u662f\u4e3a\u6b64\u800c\u5199\uff0c\u6587\u7ae0\u7740\u91cd\u70b9\u5728\u4e8e\u68b3\u7406\u51fa\u4e09\u4e2a\u6a21\u5757\u7684\u8bbe\u8ba1\u8109\u7edc\uff0c\u4fbf\u4e8e\u5927\u5bb6\u8bb0\u5fc6\u91cc\u9762\u7684api\u3002\u5728\u9700\u8981\u7684\u65f6\u5019\u80fd\u591f\u53bb\u67e5\u627e\u76f8\u5e94\u7684\u65b9\u6cd5\u3002\u4f46\u7531\u4e8ecalendar\u6a21\u5757\u4f7f\u7528\u4e0d\u591a\uff0c\u9650\u4e8e\u7bc7\u5e45\uff0c\u672c\u6587\u6ca1\u6709\u6d89\u53ca\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n 1.\u6982\u8ff0<\/strong><\/div>\n datetime\u6a21\u5757\u4e3b\u8981\u662f\u7528\u6765\u8868\u793a\u65e5\u671f\u7684\uff0c\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u5e74\u6708\u65e5\u65f6\u5206\u79d2\uff0ccalendar\u6a21\u5757\u4e3b\u8981\u662f\u7528\u6765\u8868\u793a\u5e74\u6708\u65e5\uff0c\u662f\u661f\u671f\u51e0\u4e4b\u7c7b\u7684\u4fe1\u606f\uff0ctime\u6a21\u5757\u4e3b\u8981\u4fa7\u91cd\u70b9\u5728\u65f6\u5206\u79d2\uff0c\u7c97\u7565\u4ece\u529f\u80fd\u6765\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba4\u4e3a\u4e09\u8005\u662f\u4e00\u4e2a\u4e92\u8865\u7684\u5173\u7cfb\uff0c\u5404\u81ea\u4e13\u6ce8\u4e00\u5757\u3002\u65b9\u4fbf\u7528\u6237\u4f9d\u636e\u4e0d\u540c\u7684\u4f7f\u7528\u76ee\u7684\u9009\u7528\u8d81\u624b\u7684\u6a21\u5757\u3002<\/p>\n 2.\u4ecetime\u6a21\u5757\u8bf4\u8d77<\/strong><\/div>\n \u4e3a\u4e86\u5b66\u4e60time\u6a21\u5757\uff0c\u6211\u4eec\u9700\u8981\u5148\u77e5\u9053\u51e0\u4e2a\u4e0e\u65f6\u95f4\u76f8\u5173\u7684\u6982\u5ff5\uff1a<\/p>\n \uff081\uff09epoch<\/strong><\/span><\/div>\n \u5047\u8bbe\u6211\u4eec\u8981\u5c06\u65f6\u95f4\u8868\u793a\u6210\u6beb\u79d2\u6570\uff0c\u6bd4\u65b9\u8bf41000000\u6beb\u79d2\uff0c\u90a3\u6709\u4e00\u4e2a\u95ee\u9898\u5fc5\u987b\u89e3\u51b3\uff0c\u8fd9\u4e2a1000000\u6beb\u79d2\u7684\u8d77\u70b9\u662f\u4ec0\u4e48\u65f6\u95f4\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u7684\u65f6\u95f4\u57fa\u51c6\u70b9\u662f\u4ec0\u4e48\u65f6\u95f4\uff1f\u597d\u6bd4\u6211\u8bf4\u4f60\u8eab\u9ad81.8\u7c73\uff0c\u90a3\u8fd9\u4e2a\u8eab\u9ad8\u662f\u6307\u76f8\u5bf9\u4e8e\u4f60\u7ad9\u7acb\u7684\u5730\u9762\u8bf4\u7684\u3002\u8fd9\u4e2a\u65f6\u95f4\u57fa\u51c6\u70b9\u5c31\u662fepoch\uff0c\u5728Unix\u7cfb\u7edf\u4e2d\uff0c\u8fd9\u4e2a\u57fa\u51c6\u70b9\u5c31\u662f1970\u5e741\u67081\u65e50\u70b9\u6574\u90a3\u4e2a\u65f6\u95f4\u70b9\u3002<\/p>\n \uff082\uff09GMT, UTC<\/strong><\/span><\/div>\n \u4e0a\u9762\u6211\u4eec\u8bf4epoch\u8868\u793a1970\u5e74\u7684\u8d77\u59cb\u70b9\uff0c\u90a3\u8fd9\u4e2a1970\u5e74\u53c8\u662f\u76f8\u5bf9\u4e8e\u54ea\u4e2a\u57fa\u51c6\u65f6\u95f4\u5462\uff1f\u4e00\u822c\u6765\u8bf4\uff0c\u5c31\u662f\u76f8\u5bf9\u4e8e\u683c\u6797\u5c3c\u6cbb\u65f6\u95f4\uff0c\u4e5f\u53eb\u505aGMT(Greenwich Mean Time)\u65f6\u95f4\uff0c\u8fd8\u53eb\u505aUTC(Coordinated Universal Time)\uff0c\u4e3a\u5565\u4e00\u4e2a\u65f6\u95f4\u57fa\u51c6\u6709\u4e24\u4e2a\u540d\u5b57\uff1f\u5386\u53f2\u4e0a\uff0c\u5148\u6709\u7684GMT,\u540e\u6709\u7684UTC.<\/p>\n UTC\u662f\u6211\u4eec\u73b0\u5728\u7528\u7684\u65f6\u95f4\u6807\u51c6\uff0cGMT\u662f\u8001\u7684\u65f6\u95f4\u8ba1\u91cf\u6807\u51c6\u3002UTC\u662f\u6839\u636e\u539f\u5b50\u949f\u6765\u8ba1\u7b97\u65f6\u95f4\uff0c\u800cGMT\u662f\u6839\u636e\u5730\u7403\u7684\u81ea\u8f6c\u548c\u516c\u8f6c\u6765\u8ba1\u7b97\u65f6\u95f4\u3002<\/p>\n \u6240\u4ee5\uff0c\u53ef\u4ee5\u8ba4\u4e3aUTC\u662f\u771f\u6b63\u7684\u57fa\u51c6\u65f6\u95f4\uff0cGMT\u76f8\u5bf9UTC\u7684\u504f\u5dee\u4e3a0\u3002<\/p>\n \u5728\u5b9e\u9645\u4e2d\uff0c\u6211\u4eec\u7684\u8ba1\u7b97\u673a\u4e2d\u6709\u4e00\u4e2a\u786c\u4ef6\u6a21\u5757RCT\uff0c\u91cc\u9762\u4f1a\u5b9e\u65f6\u8bb0\u5f55UTC \u65f6\u95f4\uff0c\u8be5\u6a21\u5757\u6709\u5355\u72ec\u7684\u7535\u6c60\u4f9b\u7535\uff0c\u5373\u4f7f\u5173\u673a\u4e5f\u4e0d\u5f71\u54cd\u3002<\/p>\n \u6709\u4e86epoch\u8fd9\u4e2a\u65f6\u95f4\u57fa\u51c6\uff0c\u53c8\u6709\u4e86UTC\u8fd9\u4e2a\u57fa\u51c6\u7684\u57fa\u51c6\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7cbe\u786e\u5730\u8868\u793a\u4e00\u4e2a\u65f6\u95f4\u4e86\u3002<\/p>\n \uff083\uff09DST, tzone<\/strong><\/span><\/div>\n \u5c3d\u7ba1\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u7cbe\u786e\u5730\u8868\u793a\u4e00\u4e2a\u65f6\u95f4\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u8fd8\u662f\u8981\u6839\u636e\u5730\u533a\u5b9e\u9645\u60c5\u51b5\u5bf9\u65f6\u95f4\u8fdb\u884c\u4e00\u4e2a\u8c03\u6574\uff0c\u6700\u5e38\u89c1\u7684\u5c31\u662f\u65f6\u533a\uff0ctzone\uff0c\u76f8\u4fe1\u5927\u5bb6\u90fd\u6bd4\u8f83\u719f\u6089\u3002<\/p>\n \u6b64\u65f6\uff0c\u5f53\u6211\u4eec\u8bf45\u70b95\u5206\u8fd9\u4e2a\u65f6\u95f4\u65f6\uff0c\u8fd8\u9700\u52a0\u4e0a\u662f\u54ea\u4e2a\u65f6\u533a\u76845\u70b95\u5206\u624d\u80fd\u7cbe\u786e\u8bf4\u660e\u4e00\u4e2a\u65f6\u95f4\u3002<\/p>\n \u53e6\u5916\u4e00\u4e2a\u5bf9\u65f6\u95f4\u505a\u51fa\u8c03\u6574\u7684\u5c31\u662fDST.<\/p>\n DST \u5168\u79f0\u662fDaylight Saving Time\uff0c\u662f\u8bf4\uff0c\u4e3a\u4e86\u5145\u5206\u5229\u7528\u65e5\u5149\uff0c\u51cf\u5c11\u7528\u7535\uff0c\u4eba\u4e3a\u5730\u5bf9\u65f6\u95f4\u505a\u51fa\u4e00\u4e2a\u8c03\u6574\uff0c\u8fd9\u53d6\u51b3\u4e8e\u4e0d\u540c\u56fd\u5bb6\u548c\u5730\u533a\u7684\u653f\u7b56\u6cd5\u89c4\u3002\u6bd4\u5982\u8bf4\uff0c\u5047\u8bbe\u4f60\u51ac\u59297\u70b9\u5929\u4eae\u8d77\u5e8a\uff0c\u4f46\u590f\u59296\u70b9\u5929\u4eae\uff0c\u90a3\u4e48\u5728\u590f\u5929\u5230\u6765\u65f6\u4eba\u4e3a\u5c06\u65f6\u95f4\u52a01\u4e2a\u5c0f\u65f6\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u8ba9\u4f60\u8fd8\u662f\u89c9\u5f977\u70b9\u8d77\u5e8a\uff0c\u4f46\u5b9e\u9645\u4e0a\u662f\u63d0\u524d\u4e00\u4e2a\u5c0f\u65f6\u4e86\u3002<\/p>\n \u90a3\u4e48\uff0c\u597d\u5947\u7684\u6211\u4eec\uff0c\u4e00\u5b9a\u8981\u95ee\u4e00\u95ee\uff0cpython\u662f\u5982\u4f55\u77e5\u9053tzone\u548cDST\u8fd9\u4e24\u4e2a\u7684\u503c\u5462\uff1f\u7b54\u6848\u662f\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u3002<\/p>\n \u8fd9\u91cc\u6211\u4eec\u53ea\u4ee5linux\u4e3a\u4f8b\u6765\u8bf4\u660e\u4e00\u4e0b\u3002<\/p>\n \u5728linux\u4e2d\u6709TZ\u73af\u5883\u53d8\u91cf\uff0c\u5176\u503c\u7c7b\u4f3c\u8fd9\u6837:<\/p>\n CST+08EDT,M4.1.0,M10.5.0\uff0c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u505a\u5982\u4e0b\u89e3\u8bfb\uff0c\u7528\u7a7a\u683c\u5206\u5f00\u4ed6\u4eec\uff0c\u5206\u6210\u4e09\u90e8\u5206<\/p>\n CST+08 EDT, M4.1.0,M10.5.0<\/p>\n \u7b2c\u4e00\u90e8\u5206\u4e2d\u7684CST\u8868\u793a\u65f6\u533a\u7684\u540d\u5b57\uff0c\u5373China Standard Time\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u8bf4\u7684\u5317\u4eac\u65f6\u95f4\uff0c+8\u8868\u793a\u5317\u4eac\u65f6\u95f4\u52a0\u4e0a8\u5c0f\u65f6\u5c31\u662fUTC\u65f6\u95f4<\/p>\n \u7b2c\u4e8c\u90e8\u5206EDT\u8868\u793aDST\u7684\u540d\u5b57\uff0c\u6211\u4eec\u8bf4DST\u662f\u56e0\u5404\u4e2a\u56fd\u5bb6\u5730\u533a\u7684\u653f\u7b56\u6cd5\u89c4\u4e0d\u540c\u800c\u4e0d\u540c\u7684\uff0cEDT\u540e\u9762\u4e5f\u53ef\u4ee5\u50cfCST\u540e\u9762\u4e00\u6837\u52a0\u4e00\u4e2a\u65f6\u95f4\u8c03\u6574\u503c\uff0c\u4f46\u7531\u4e8e\u6211\u4eec\u56fd\u5185\u53ea\u572886\u5e74\u523092\u5e74\u5b9e\u884c\u8fc7\u4e00\u6bb5\u65f6\u95f4DST\uff0c\u73b0\u5728\u5df2\u7ecf\u5e9f\u6b62\uff0c\u6240\u4ee5\u540e\u9762\u4e0d\u7528\u52a0\u8c03\u6574\u65f6\u95f4\u3002<\/p>\n \u7b2c\u4e09\u90e8\u5206\u8868\u793a\u7684\u662f\u5b9e\u884cDST\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\uff0c\u6211\u4eec\u5c31\u4e0d\u7ec6\u89e3\u8bfb\u4e86\u3002<\/p>\n \uff084\uff09\u65f6\u95f4\u7684\u8868\u793a\uff0c\u83b7\u53d6\uff0c\u8f6c\u6362<\/strong><\/span><\/div>\n time\u6a21\u5757\u4e2d\u83b7\u53d6\u65f6\u95f4\u7684\u57fa\u672c\u65b9\u6cd5\u662f<\/p>\n t = time.time()<\/pre>\n |