python 3 timeモジュール解釈

6244 ワード

time()
time()モジュールはObjectクラスから継承され、datetime()モジュールはObjectの下のDate()モジュールから継承されます.
timeが提供する機能は、オペレーティングシステムのレベルに近づき、その記述可能な日付範囲は1970〜2038の間に限定され、より広い日付を処理するにはdatetimeモジュールを使用する必要がある.
time()内蔵関数
time.time()現在のタイムスタンプsecsを返す
print(time.time())
1508977857.868619

タイムスタンプは、localtime、ctime、gmtimeなどのtime()モジュールの他の内蔵関数に使用できます.
time.localtime([secs])
タイムスタンプを受信し、指定したタイムスタンプの のタイムメタグループを返し、パラメータは空白のまま、 の現在のタイムメタグループを返します.
import time
t = time.time()    #      
a = time.localtime(t)  #            
b = time.gmtime(t)     #              

time.gmtime()
タイムスタンプを受信し、グリニッジ天文時間のタイムメタグループを返します.
import time
t = time.time()    #      
a = time.localtime(t)  #            
b = time.gmtime(t)     #              
localtime() gmtime() , , 。
localtime()もgmtime()も受信timeである.time()はタイムスタンプを返し、結果はすべてタイムメタグループです.受信時間メタグループの関数はasctime,strftimeであり,
time.asctime([tupletime])
時間タプルを受け入れて、「Tue Dec 11 18:07:14 2008」(2008年12月11日火曜日18時07分14秒)の24文字の文字列を返します.
import time
t = time.time()    #      
a = time.localtime(t)  #            
b = time.gmtime(t)     #              

print('time.asctime %s' %(time.asctime(a)))   #         
print('time.asctime %s' %(time.asctime(b)))   #         

time.strftime(srt_format[,tupletime])
受信時間メタグループ、ローカル時間を返します.最初のパラメータは文字列形式のフォーマット文字です.
import time
t = time.time()    #      
a = time.localtime(t)  #            
b = time.gmtime(t)     #              

print('time.asctime %s' %(time.asctime(a)))   #         
print('time.asctime %s' %(time.asctime(b)))   #         
print('time.strftime %s' %(time.strftime('%Y-%m-%d %H:%M:%S',a)))  #            

結果
time.asctime Thu Oct 26 08:49:50 2017
time.asctime Thu Oct 26 00:49:50 2017
time.strftime 2017-10-26 08:49:50

日付書式記号
フォーマット記号はdatetime()モジュールに統一的に適用され、よく使われる%Y-%m-%d%H:%M:%Sおよび%c(標準時間)
      
%a              :    ,     Mon
%A              :    ,   Monday

%b              :   ,     Jan
%B              :   ,     January

%c      datetime      , 03/08/15 23:01:26

%d                    

%f         :   : [0,999999]

%H     24         
%I     12         

%j                  [001,366]

%m           [0,12]
%M             [0,59]

%P             –AM or PM

%S                [0,61]

%U                       
%W                       

%w            ,   [0, 6],6     

%x             :03/08/15
%X             :23:22:08
%y              15
%Y              2015
%z     utc      (       ,      )
%Z        (       ,      )

time.sleep(secs)が最もよく使われる
休止時間指定秒数
import time
print('     %s' %(time.ctime()))
time.sleep(3)
print('     %s' %(time.ctime()))