{"id":1037,"date":"2023-03-24T09:47:07","date_gmt":"2023-03-24T01:47:07","guid":{"rendered":""},"modified":"2023-03-24T09:47:07","modified_gmt":"2023-03-24T01:47:07","slug":"Python \u65e5\u671f\u4e0e\u65f6\u95f4","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1037.html","title":{"rendered":"Python \u65e5\u671f\u4e0e\u65f6\u95f4"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

Python \u65e5\u671f\u4e0e\u65f6\u95f4<\/h1>\n

\u641e\u61c2Python\u65e5\u671f\u4e0e\u65f6\u95f4\u7684\u683c\u5f0f\u5316\u548c\u8f6c\u6362\u7b49\u64cd\u4f5c<\/span>\n <\/div>\n

\n Python \u7a0b\u5e8f\u80fd\u7528\u5f88\u591a\u65b9\u5f0f\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\uff0c\u8f6c\u6362\u65e5\u671f\u683c\u5f0f\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u529f\u80fd\u3002Python \u63d0\u4f9b\u4e86\u4e00\u4e2a time \u548c calendar \u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u683c\u5f0f\u5316\u65e5\u671f\u548c\u65f6\u95f4\u3002\n <\/div>\n
\n \u65f6\u95f4\u95f4\u9694\u662f\u4ee5\u79d2\u4e3a\u5355\u4f4d\u7684\u6d6e\u70b9\u5c0f\u6570\u3002\u6bcf\u4e2a\u65f6\u95f4\u6233\u90fd\u4ee5\u81ea\u4ece 1970 \u5e74 1 \u6708 1 \u65e5\u5348\u591c\uff08\u5386\u5143\uff09\u7ecf\u8fc7\u4e86\u591a\u957f\u65f6\u95f4\u6765\u8868\u793a\u3002Python \u7684 time \u6a21\u5757\u4e0b\u6709\u5f88\u591a\u51fd\u6570\u53ef\u4ee5\u8f6c\u6362\u5e38\u89c1\u65e5\u671f\u683c\u5f0f\u3002\u5982\u51fd\u6570 time.time() \u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233, \u5982\u4e0b\u5b9e\u4f8b:\n <\/div>\n
\n
 import<\/span> time
ticks = time.time()<\/span>
print(\"\u5f53\u524d\u65f6\u95f4\u6233\u4e3a:\", ticks<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
\u5f53\u524d\u65f6\u95f4\u6233\u4e3a: 1594644577.9761147<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u65f6\u95f4\u6233\u5355\u4f4d\u6700\u9002\u4e8e\u505a\u65e5\u671f\u8fd0\u7b97\u3002\u4f46\u662f1970\u5e74\u4e4b\u524d\u7684\u65e5\u671f\u5c31\u65e0\u6cd5\u4ee5\u6b64\u8868\u793a\u4e86\u3002\u592a\u9065\u8fdc\u7684\u65e5\u671f\u4e5f\u4e0d\u884c\uff0cUNIX\u548cWindows\u53ea\u652f\u6301\u52302038\u5e74\u3002\n <\/div>\n

\u65f6\u95f4\u5143\u7ec4<\/h2>\n
\n \u5f88\u591aPython\u51fd\u6570\u7528\u4e00\u4e2a\u5143\u7ec4\u88c5\u8d77\u6765\u76849\u7ec4\u6570\u5b57\u5904\u7406\u65f6\u95f4:\n <\/div>\n\n\n\n\n\n\n\n\n\n\n\n\n
\u5b57\u6bb5<\/td>\n\u503c<\/td>\n<\/tr>\n
4\u4f4d\u6570\u5e74<\/td>\n2008<\/td>\n<\/tr>\n
\u6708 <\/td>\n1 \u5230 12<\/td>\n<\/tr>\n
\u65e5 <\/td>\n1\u523031<\/td>\n<\/tr>\n
\u5c0f\u65f6 <\/td>\n0\u523023<\/td>\n<\/tr>\n
\u5206\u949f <\/td>\n0\u523059<\/td>\n<\/tr>\n
\u79d2 <\/td>\n0\u523061 (60\u621661 \u662f\u95f0\u79d2)<\/td>\n<\/tr>\n
\u4e00\u5468\u7684\u7b2c\u51e0\u65e5 <\/td>\n0\u52306 (0\u662f\u5468\u4e00)<\/td>\n<\/tr>\n
\u4e00\u5e74\u7684\u7b2c\u51e0\u65e5 <\/td>\n1\u5230366 (\u5112\u7565\u5386)<\/td>\n<\/tr>\n
\u590f\u4ee4\u65f6 <\/td>\n-1, 0, 1, -1\u662f\u51b3\u5b9a\u662f\u5426\u4e3a\u590f\u4ee4\u65f6\u7684\u65d7\u5e1c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n \u4e0a\u8ff0\u4e5f\u5c31\u662fstruct_time\u5143\u7ec4\u3002\u8fd9\u79cd\u7ed3\u6784\u5177\u6709\u5982\u4e0b\u5c5e\u6027\uff1a\n <\/div>\n\n\n\n\n\n\n\n\n\n\n\n\n
\u5c5e\u6027<\/td>\n\u503c<\/td>\n<\/tr>\n
tm_year <\/td>\n2008<\/td>\n<\/tr>\n
tm_mon<\/td>\n1 \u5230 12<\/td>\n<\/tr>\n
tm_mday <\/td>\n1 \u5230 31<\/td>\n<\/tr>\n
tm_hour <\/td>\n0 \u5230 23<\/td>\n<\/tr>\n
tm_min <\/td>\n0 \u5230 59<\/td>\n<\/tr>\n
tm_sec <\/td>\n0 \u5230 61 (60\u621661 \u662f\u95f0\u79d2)<\/td>\n<\/tr>\n
tm_wday <\/td>\n0\u52306 (0\u662f\u5468\u4e00)<\/td>\n<\/tr>\n
tm_yday <\/td>\n\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929\uff0c1 \u5230 366<\/td>\n<\/tr>\n
tm_isdst <\/td>\n\u662f\u5426\u4e3a\u590f\u4ee4\u65f6\uff0c\u503c\u6709\uff1a1(\u590f\u4ee4\u65f6)\u30010(\u4e0d\u662f\u590f\u4ee4\u65f6)\u3001-1(\u672a\u77e5)\uff0c\u9ed8\u8ba4 -1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u83b7\u53d6\u5f53\u524d\u65f6\u95f4<\/h2>\n
\n \u4ece\u8fd4\u56de\u6d6e\u70b9\u6570\u7684\u65f6\u95f4\u6233\u65b9\u5f0f\u5411\u65f6\u95f4\u5143\u7ec4\u8f6c\u6362\uff0c\u53ea\u8981\u5c06\u6d6e\u70b9\u6570\u4f20\u9012\u7ed9\u5982localtime\u4e4b\u7c7b\u7684\u51fd\u6570\u3002\n <\/div>\n
\n
 import<\/span> time
localtime = time.localtime(time.time())<\/span>
print(\"\u672c\u5730\u65f6\u95f4\u4e3a :\", localtime<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
\u672c\u5730\u65f6\u95f4\u4e3a : time.struct_time(tm_year=2020, tm_mon=7, tm_mday=13, tm_hour=13, tm_min=0, tm_sec=37, tm_wday=0, tm_yday=195, tm_isdst=0)<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u83b7\u53d6\u683c\u5f0f\u5316\u7684\u65f6\u95f4<\/h2>\n
\n \u4f60\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u53d6\u5404\u79cd\u683c\u5f0f\uff0c\u4f46\u662f\u6700\u7b80\u5355\u7684\u83b7\u53d6\u53ef\u8bfb\u7684\u65f6\u95f4\u6a21\u5f0f\u7684\u51fd\u6570\u662fasctime():\n <\/div>\n
\n
 import<\/span> time
localtime = time.asctime(time.localtime(time.time()))<\/span>
print(\"\u672c\u5730\u65f6\u95f4\u4e3a :\", localtime<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
\u672c\u5730\u65f6\u95f4\u4e3a : Mon Jul 13 13:02:03 2020<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u683c\u5f0f\u5316\u65e5\u671f<\/h2>\n
\n \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 time \u6a21\u5757\u7684 strftime \u65b9\u6cd5\u6765\u683c\u5f0f\u5316\u65e5\u671f\u3002\n <\/div>\n
\n
 import<\/span> time
# \u683c\u5f0f\u5316\u62102020-07-13 13:06:04\u5f62\u5f0f<\/span>
print(time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())<\/span>)
# \u683c\u5f0f\u5316\u6210Mon Jul 13 13:06:04 2020\u5f62\u5f0f<\/span>
print(time.strftime(\"%a %b %d %H:%M:%S %Y\", time.localtime())<\/span>)
# \u5c06\u683c\u5f0f\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233<\/span>
a = \"Mon Jul 13 13:06:04 2020\"
print(time.mktime(time.strptime(a,\"%a %b %d %H:%M:%S %Y\"))<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
2020-07-13 13:06:53
Mon Jul 13 13:06:53 2020
1594645564.0<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n python\u4e2d\u65f6\u95f4\u65e5\u671f\u683c\u5f0f\u5316\u7b26\u53f7\uff1a<\/b>\n <\/div>\n

%y \u4e24\u4f4d\u6570\u7684\u5e74\u4efd\u8868\u793a\uff0800-99\uff09<\/span>
\n %Y \u56db\u4f4d\u6570\u7684\u5e74\u4efd\u8868\u793a\uff08000-9999\uff09<\/span>
\n %m \u6708\u4efd\uff0801-12\uff09<\/span>
\n %d \u6708\u5185\u4e2d\u7684\u4e00\u5929\uff080-31\uff09<\/span>
\n %H 24\u5c0f\u65f6\u5236\u5c0f\u65f6\u6570\uff080-23\uff09<\/span>
\n %I 12\u5c0f\u65f6\u5236\u5c0f\u65f6\u6570\uff0801-12\uff09<\/span>
\n %M \u5206\u949f\u6570\uff0800=59\uff09<\/span>
\n %S \u79d2\uff0800-59\uff09<\/span>
\n %a \u672c\u5730\u7b80\u5316\u661f\u671f\u540d\u79f0<\/span>
\n %A \u672c\u5730\u5b8c\u6574\u661f\u671f\u540d\u79f0<\/span>
\n %b \u672c\u5730\u7b80\u5316\u7684\u6708\u4efd\u540d\u79f0<\/span>
\n %B \u672c\u5730\u5b8c\u6574\u7684\u6708\u4efd\u540d\u79f0<\/span>
\n %c \u672c\u5730\u76f8\u5e94\u7684\u65e5\u671f\u8868\u793a\u548c\u65f6\u95f4\u8868\u793a<\/span>
\n %j \u5e74\u5185\u7684\u4e00\u5929\uff08001-366\uff09<\/span>
\n %p \u672c\u5730A.M.\u6216P.M.\u7684\u7b49\u4ef7\u7b26<\/span>
\n %U \u4e00\u5e74\u4e2d\u7684\u661f\u671f\u6570\uff0800-53\uff09\u661f\u671f\u5929\u4e3a\u661f\u671f\u7684\u5f00\u59cb<\/span>
\n %w \u661f\u671f\uff080-6\uff09\uff0c\u661f\u671f\u5929\u4e3a\u661f\u671f\u7684\u5f00\u59cb<\/span>
\n %W \u4e00\u5e74\u4e2d\u7684\u661f\u671f\u6570\uff0800-53\uff09\u661f\u671f\u4e00\u4e3a\u661f\u671f\u7684\u5f00\u59cb<\/span>
\n %x \u672c\u5730\u76f8\u5e94\u7684\u65e5\u671f\u8868\u793a<\/span>
\n %X \u672c\u5730\u76f8\u5e94\u7684\u65f6\u95f4\u8868\u793a<\/span>
\n %Z \u5f53\u524d\u65f6\u533a\u7684\u540d\u79f0<\/span>
\n %% %\u53f7\u672c\u8eab<\/span> <\/p>\n

\u83b7\u53d6\u65e5\u5386<\/h2>\n
\n Calendar\u6a21\u5757\u6709\u5f88\u5e7f\u6cdb\u7684\u65b9\u6cd5\u7528\u6765\u5904\u7406\u5e74\u5386\u548c\u6708\u5386\uff0c\u4f8b\u5982\u6253\u5370\u67d0\u6708\u7684\u6708\u5386\uff1a\n <\/div>\n
\n
 import<\/span> calendar
cal = calendar.month(2020, 7<\/span>)
print(\"\u8f93\u51fa2020\u5e747\u6708\u4efd\u65e5\u5386\"<\/span>)
print(cal<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u7ed3\u679c\uff1a\n <\/div>\n
\n
\u8f93\u51fa2020\u5e747\u6708\u4efd\u65e5\u5386<\/span> \n
\n    July 2020<\/span> \n
\nMo Tu We Th Fr Sa Su<\/span> \n
\n       1  2  3  4  5<\/span> \n
\n 6  7  8  9 10 11 12<\/span> \n
\n13 14 15 16 17 18 19<\/span> \n
\n20 21 22 23 24 25 26<\/span> \n
\n27 28 29 30 31<\/span><\/code><\/pre>\n<\/p><\/div>\n

Time \u6a21\u5757<\/h2>\n
\n Time \u6a21\u5757\u5305\u542b\u4e86\u4ee5\u4e0b\u5185\u7f6e\u51fd\u6570\uff0c\u65e2\u6709\u65f6\u95f4\u5904\u7406\u7684\uff0c\u4e5f\u6709\u8f6c\u6362\u65f6\u95f4\u683c\u5f0f\u7684\uff1a\n <\/div>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u51fd\u6570\u3001\u63cf\u8ff0\u548c\u793a\u4f8b<\/td>\n<\/tr>\n
time.altzone<\/span>
\u8fd4\u56de\u683c\u6797\u5a01\u6cbb\u897f\u90e8\u7684\u590f\u4ee4\u65f6\u5730\u533a\u7684\u504f\u79fb\u79d2\u6570\u3002\u5982\u679c\u8be5\u5730\u533a\u5728\u683c\u6797\u5a01\u6cbb\u4e1c\u90e8\u4f1a\u8fd4\u56de\u8d1f\u503c\uff08\u5982\u897f\u6b27\uff0c\u5305\u62ec\u82f1\u56fd\uff09\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(\"time.altzone %d \" % time.altzone<\/span>)
time.altzone 0 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.asctime([tupletime])<\/span>
\u8fd4\u56de\u4e00\u4e2a\u5f62\u5f0f\u4e3a\"Tue Jul 14 11:39:58 2020\"\uff082020\u5e747\u670814\u65e5 \u5468\u4e8c11\u65f639\u520658\u79d2\uff09\u7684\u5b57\u7b26\u4e32\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> t = time.localtime()<\/span>
>>> print(time.asctime(t)<\/span>)
Thu Apr 7 10:36:20 2016 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.clock()<\/span>
\u7528\u4ee5\u6d6e\u70b9\u6570\u8ba1\u7b97\u7684\u79d2\u6570\u8fd4\u56de\u5f53\u524d\u7684CPU\u65f6\u95f4\u3002\u7528\u6765\u8861\u91cf\u4e0d\u540c\u7a0b\u5e8f\u7684\u8017\u65f6\uff0c\u6bd4time.time()\u66f4\u6709\u7528\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.perf_counter()<\/span>)
>>> print(time.process_time()<\/span>)
22482074.841124818
0.013232696
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.ctime([secs])<\/span>
\u4f5c\u7528\u76f8\u5f53\u4e8easctime(localtime(secs))\uff0c\u672a\u7ed9\u53c2\u6570\u76f8\u5f53\u4e8easctime() <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.ctime()<\/span>)
Tue Jul 14 11:45:21 2020 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.gmtime([secs])<\/span>
\u63a5\u6536\u65f6\u95f4\u6233\u5e76\u8fd4\u56de\u683c\u6797\u5a01\u6cbb\u5929\u6587\u65f6\u95f4\u4e0b\u7684\u65f6\u95f4\u5143\u7ec4t\u3002\u6ce8\uff1at.tm_isdst\u59cb\u7ec8\u4e3a0 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.gmtime(1593508609.34375)<\/span>)
time.struct_time(tm_year=2020, tm_mon=6, tm_mday=30, tm_hour=9, tm_min=16, tm_sec=49, tm_wday=1, tm_yday=182, tm_isdst=0) <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.localtime([secs]<\/span>
\u63a5\u6536\u65f6\u95f4\u6233\u5e76\u8fd4\u56de\u5f53\u5730\u65f6\u95f4\u4e0b\u7684\u65f6\u95f4\u5143\u7ec4t\uff08t.tm_isdst\u53ef\u53d60\u62161\uff0c\u53d6\u51b3\u4e8e\u5f53\u5730\u5f53\u65f6\u662f\u4e0d\u662f\u590f\u4ee4\u65f6\uff09\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.localtime(1593508609.34375)<\/span>)
time.struct_time(tm_year=2020, tm_mon=6, tm_mday=30, tm_hour=9, tm_min=16, tm_sec=49, tm_wday=1, tm_yday=182, tm_isdst=0) <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.mktime(tupletime)<\/span>
\u63a5\u53d7\u65f6\u95f4\u5143\u7ec4\u5e76\u8fd4\u56de\u65f6\u95f4\u6233\uff081970\u7eaa\u5143\u540e\u7ecf\u8fc7\u7684\u6d6e\u70b9\u79d2\u6570\uff09\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> t = (2016, 2, 17, 17, 3, 38, 1, 48, 0)<\/span>
>>> secs = time.mktime(t)<\/span>
>>> print(secs<\/span>)
>>> print(time.asctime(time.localtime(secs))<\/span>)
1455728618.0
Wed Feb 17 17:03:38 2016 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.sleep(secs)<\/span>
\u63a8\u8fdf\u8c03\u7528\u7ebf\u7a0b\u7684\u8fd0\u884c\uff0csecs\u6307\u79d2\u6570\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.ctime()<\/span>)
>>> time.sleep(3) >>> print(time.ctime()<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.strftime(fmt[,tupletime])<\/span>
\u63a5\u6536\u4ee5\u65f6\u95f4\u5143\u7ec4\uff0c\u5e76\u8fd4\u56de\u4ee5\u53ef\u8bfb\u5b57\u7b26\u4e32\u8868\u793a\u7684\u5f53\u5730\u65f6\u95f4\uff0c\u683c\u5f0f\u7531fmt\u51b3\u5b9a\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())<\/span>)
2020-07-14 11:57:27 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.strptime(str,fmt='%a %b %d %H:%M:%S %Y')<\/span>
\u6839\u636efmt\u7684\u683c\u5f0f\u628a\u4e00\u4e2a\u65f6\u95f4\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a\u65f6\u95f4\u5143\u7ec4\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> struct_time = time.strptime(\"30 Nov 00\", \"%d %b %y\")<\/span>
>>> print(struct_time<\/span>)
time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1) <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.time()<\/span>
\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u7684\u65f6\u95f4\u6233\uff081970\u7eaa\u5143\u540e\u7ecf\u8fc7\u7684\u6d6e\u70b9\u79d2\u6570\uff09\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.time()<\/span>)
1594728225.9022148 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.tzset()<\/span>
\u6839\u636e\u73af\u5883\u53d8\u91cfTZ\u91cd\u65b0\u521d\u59cb\u5316\u65f6\u95f4\u76f8\u5173\u8bbe\u7f6e\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> import<\/span> os
>>> os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'<\/span>
>>> time.tzset()
>>> print(time.strftime('%X %x %Z')<\/span>)
>>> os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'<\/span>
>>> time.tzset()
>>> print(time.strftime('%X %x %Z')<\/span>)
08:08:47 07\/14\/20 EDT
22:08:47 07\/14\/20 AEST <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.perf_counter()<\/span>
\u8fd4\u56de\u8ba1\u65f6\u5668\u7684\u7cbe\u51c6\u65f6\u95f4\uff0c\u7531\u4e8e\u8fd4\u56de\u503c\u7684\u57fa\u51c6\u70b9\u662f\u672a\u5b9a\u4e49\u7684\uff0c\u6240\u4ee5\uff0c\u53ea\u6709\u8fde\u7eed\u8c03\u7528\u7684\u7ed3\u679c\u4e4b\u95f4\u7684\u5dee\u624d\u662f\u6709\u6548\u7684\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> time.sleep(1)<\/span>
>>> a = time.perf_counter()<\/span>
>>> print(a<\/span>)
>>> time.sleep(1)<\/span>
>>> b = time.perf_counter()<\/span>
>>> print(b<\/span>)
10130931.42668036
10130932.427768432 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n
time.process_time()<\/span>
\u8fd4\u56de\u5f53\u524d\u8fdb\u7a0b\u6267\u884c CPU \u7684\u65f6\u95f4\u603b\u548c\uff0c\u4e0d\u5305\u542b\u7761\u7720\u65f6\u95f4\u3002 <\/p>\n
\n
 >>> import<\/span> time
>>> print(time.process_time()<\/span>)
0.013454055 <\/span><\/code><\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\n Time\u6a21\u5757\u5305\u542b\u4e86\u4ee5\u4e0b2\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u5c5e\u6027\uff1a\n <\/div>\n

time.timezone\uff1a<\/b>\u662f\u5f53\u5730\u65f6\u533a\uff08\u672a\u542f\u52a8\u590f\u4ee4\u65f6\uff09\u8ddd\u79bb\u683c\u6797\u5a01\u6cbb\u7684\u504f\u79fb\u79d2\u6570\uff08>0\uff0c\u7f8e\u6d32;<=0\u5927\u90e8\u5206\u6b27\u6d32\uff0c\u4e9a\u6d32\uff0c\u975e\u6d32\uff09\u3002<\/span>
\n time.tzname\uff1a<\/b>\u5305\u542b\u4e00\u5bf9\u6839\u636e\u60c5\u51b5\u7684\u4e0d\u540c\u800c\u4e0d\u540c\u7684\u5b57\u7b26\u4e32\uff0c\u5206\u522b\u662f\u5e26\u590f\u4ee4\u65f6\u7684\u672c\u5730\u65f6\u533a\u540d\u79f0\uff0c\u548c\u4e0d\u5e26\u7684\u3002<\/span> <\/p>\n

\u65e5\u5386\uff08Calendar\uff09\u6a21\u5757<\/h2>\n
\n \u6b64\u6a21\u5757\u7684\u51fd\u6570\u90fd\u662f\u65e5\u5386\u76f8\u5173\u7684\uff0c\u4f8b\u5982\u6253\u5370\u67d0\u6708\u7684\u5b57\u7b26\u6708\u5386\u3002\u661f\u671f\u4e00\u9ed8\u8ba4\u662f\u6bcf\u5468\u7b2c\u4e00\u5929\uff0c\u661f\u671f\u5929\u9ed8\u8ba4\u662f\u6700\u540e\u4e00\u5929\u3002\u6a21\u5757\u5305\u542b\u4e86\u4ee5\u4e0b\u5185\u7f6e\u51fd\u6570\uff1a\n <\/div>\n

calendar.calendar(year,w=2,l=1,c=6)\uff1a<\/b>\u8fd4\u56de\u4e00\u4e2a\u591a\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u7684year\u5e74\u5e74\u5386\uff0c3\u4e2a\u6708\u4e00\u884c\uff0c\u95f4\u9694\u8ddd\u79bb\u4e3ac\u3002<\/span>
\n calendar.firstweekday()\uff1a<\/b>\u8fd4\u56de\u5f53\u524d\u6bcf\u5468\u8d77\u59cb\u65e5\u671f\u7684\u8bbe\u7f6e\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u9996\u6b21\u8f7d\u5165caendar\u6a21\u5757\u65f6\u8fd4\u56de0\uff0c\u5373\u661f\u671f\u4e00\u3002<\/span>
\n calendar.isleap(year)\uff1a<\/b>\u662f\u95f0\u5e74\u8fd4\u56de True\uff0c\u5426\u5219\u4e3a false\u3002<\/span>
\n calendar.leapdays(y1,y2)\uff1a<\/b>\u8fd4\u56de\u5728Y1\uff0cY2\u4e24\u5e74\u4e4b\u95f4\u7684\u95f0\u5e74\u603b\u6570\u3002<\/span>
\n calendar.month(year,month,w=2,l=1)\uff1a<\/b>\u8fd4\u56de\u4e00\u4e2a\u591a\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u7684year\u5e74month\u6708\u65e5\u5386,\u6bcf\u65e5\u5bbd\u5ea6\u95f4\u9694\u4e3aw\u5b57\u7b26\u3002<\/span>
\n calendar.monthcalendar(year,month)\uff1a<\/b>\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u7684\u5355\u5c42\u5d4c\u5957\u5217\u8868\u3002\u6bcf\u4e2a\u5b50\u5217\u8868\u88c5\u8f7d\u4ee3\u8868\u4e00\u4e2a\u661f\u671f\u7684\u6574\u6570\u3002<\/span>
\n calendar.monthrange(year,month)\uff1a<\/b>\u8fd4\u56de\u4e24\u4e2a\u6574\u6570\u3002\u7b2c\u4e00\u4e2a\u662f\u8be5\u6708\u7684\u661f\u671f\u51e0\uff0c\u7b2c\u4e8c\u4e2a\u662f\u8be5\u6708\u6709\u51e0\u5929\u3002<\/span>
\n calendar.prcal(year,w=2,l=1,c=6)\uff1a<\/b>\u76f8\u5f53\u4e8e print calendar.calendar(year,w,l,c).<\/span>
\n calendar.prmonth(year,month,w=2,l=1)\uff1a<\/b>\u76f8\u5f53\u4e8e print calendar.calendar\uff08year\uff0cw\uff0cl\uff0cc\uff09\u3002<\/span>
\n calendar.setfirstweekday(weekday)\uff1a<\/b>\u8bbe\u7f6e\u6bcf\u5468\u7684\u8d77\u59cb\u65e5\u671f\u7801\u30020\uff08\u661f\u671f\u4e00\uff09\u52306\uff08\u661f\u671f\u65e5\uff09\u3002<\/span>
\n calendar.timegm(tupletime)\uff1a<\/b>\u548ctime.gmtime\u76f8\u53cd\uff1a\u63a5\u53d7\u4e00\u4e2a\u65f6\u95f4\u5143\u7ec4\u5f62\u5f0f\uff0c\u8fd4\u56de\u8be5\u65f6\u523b\u7684\u65f6\u95f4\u6233\uff081970\u7eaa\u5143\u540e\u7ecf\u8fc7\u7684\u6d6e\u70b9\u79d2\u6570\uff09\u3002<\/span>
\n calendar.weekday(year,month,day)\uff1a<\/b>\u8fd4\u56de\u7ed9\u5b9a\u65e5\u671f\u7684\u65e5\u671f\u7801\u30020\uff08\u661f\u671f\u4e00\uff09\u52306\uff08\u661f\u671f\u65e5\uff09\u3002\u6708\u4efd\u4e3a 1\uff08\u4e00\u6708\uff09 \u5230 12\uff0812\u6708\uff09\u3002<\/span>
\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Python \u65e5\u671f\u4e0e\u65f6\u95f4zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-1037","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1037"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1037"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1037\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}