1. 程式人生 > >一 time與datetime模塊

一 time與datetime模塊

偏移 形式 print float str 元組 date format form

  • 時間戳(timestamp):通常來說,時間戳表示的是從1970年1月1日00:00:00開始按秒計算的偏移量。我們運行“type(time.time())”,返回的是float類型。
  • 格式化的時間字符串(Format String)
  • 結構化的時間(struct_time):struct_time元組共有9個元素共九個元素:(年,月,日,時,分,秒,一年中第幾周,一年中第幾天,夏令時)
import time
#--------------------------我們先以當前時間為準,讓大家快速認識三種形式的時間
print(time.time()) # 時間戳:1487130156.419527
print(time.strftime("%Y-%m-%d %X")) #格式化的時間字符串:‘2017-02-15 11:40:53‘

print(time.localtime()) #本地時區的struct_time
print(time.gmtime())    #UTC時區的struct_time

  

一 time與datetime模塊