標籤:localtime 單位 運行 fse rom lock val imp strftime
1 #encoding=utf-8 2 import time 3 4 # 返回時間戳記 5 print time.time() 6 7 # 延遲運行單位為s,如下為延遲3s 8 time.sleep(3) 9 10 # 轉換時間戳記為時間元組(時間對象),自1970+second,其second為秒數11 print time.gmtime(4)12 13 # 轉換時間戳記為本機物件14 print time.localtime()15 16 # 將時間戳記轉換為字串17 print time.asctime(time.localtime())18 19 # 將時間戳記轉換為字串20 print time.ctime(5)21 22 # 將本地時間轉換為時間戳記23 t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)24 print time.mktime(t)25 26 # 將時間對象轉換為規範性字串(常用),格式如下27 ‘‘‘28 %Y Year with century as a decimal number.29 %m Month as a decimal number [01,12].30 %d Day of the month as a decimal number [01,31].31 %H Hour (24-hour clock) as a decimal number [00,23].32 %M Minute as a decimal number [00,59].33 %S Second as a decimal number [00,61].34 %z Time zone offset from UTC.35 %a Locale‘s abbreviated weekday name.36 %A Locale‘s full weekday name.37 %b Locale‘s abbreviated month name.38 %B Locale‘s full month name.39 %c Locale‘s appropriate date and time representation.40 %I Hour (12-hour clock) as a decimal number [01,12].41 %p Locale‘s equivalent of either AM or PM.42 ‘‘‘43 print time.strftime(‘%Y-%m-%d %H-%M-%S‘,t)44 45 # 將時間字串根據指定的格式化符轉換成數組形式的時間46 struct_time = time.strptime("30 Nov 00", "%d %b %y")47 print struct_time
python的time模組