python操作時間のいくつかの重要な関数をまとめました。

1768 ワード

この記事を見てください。
http://qinxuye.me/article/details-about-time-module-in-python/
タイムスタンプから時間構造体まで:
time.locatime([secs])
時間構造体からタイムスタンプに変換:
time.mktime(t)
時間構造体から指定された書式の文字列を印刷します。
time.streftime(format[、 t]
指定された書式の文字列から時間構造体を取得します。
time.streptime(string[、 フォーマット)  
フォーマットの説明:
a-abbreeviateted weekday name%A-full weekday name%b-abbreviaed moth name%B-full moth name%c-preferred date and time representation%C-century number(the year divided by 100,rangee%tommmthe%mmmmmmmthe+the+the%totoname%totoname 100,rame%mmmmmmmmmmmmmmmmmmmdae e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e%G,but without the century%G-4-digit year coress ponding to the ISO week number.%h-same as%b%H-hour,using a 24-hour clock(00 to 23)%I-hour,using a 12-hour clock(01 to-mont)m-minute%n-newline character%p-einther am or pm accoding to the given time value%r-time in a.m.and p.m.notation%R-time in 24 hour notation%S-second%t-tab character%T-current%t-current%inininininininininininininininininininininininininininininininininininininininininininine%a%a%a%a%t%t%t%t%t%t%T-ttttttttxxxxxxxxxxxxxxxxxxxxday=1%U-week number of the current year、starting with the first Sunday as the first day of the first week%V-The ISO 8601 week number of the current year(01 to 53)、where week 1 is the first week that has atlast 4 days 4 days the the currewentstarting with the first Monday as the first day of the first week%w-day of the week as a decimal,Sundy=0%x-preferred date representation without the time%X-preferred time representer 99%Y-year including the century%Z or%z-time zone or name or abreviation%-a liter%character
たとえば現在の時間を印刷します。
time.strftime('%Y-%m-%d %H:%M:%S')