1. 程式人生 > >python 時間函式小總結

python 時間函式小總結

時間戳:從1970年1月1日00:00:00開始按秒計算的偏移量。舉個例子,現在是2017年6月11的下午16:54:32,那麼print(time.time())輸出的值是1497171320.99就代表現在的時間戳。 元組(struct_time):struct_time元組共有9個元素。gmtime(),localtime(),strptime()這三個函式會返回struct_time元組。下面的表格會列出struct_time的9個元素的具體情況

time.localtime(t)    時間戳轉換為struct_time,有引數是固定時間,沒有引數是當前時間

time.time()  返回當前時間的時間戳

time.mktime(t) 將一個struct_time t 轉換為時間戳

time.strftime(" %Y-%m-%d ",a)將一個struct_time a 轉換為指定格式的時間字串,%Y%m%d%H%M%S依次代表年月日時分秒

time.strptime("2017-6-11 17:51:30","%Y-%m-%d %H:%M:%S")把一個格式化時間字串轉化為struct_time