1. 程式人生 > >Python time 的應用

Python time 的應用

oca python UNC div 夏令時 ima 時區 sleep lee

  • 測試如下:

    import time
    
    print("chenfulin")
    
    # 返回格林威治西部的夏令時區
    print("time.altzone %d" % time.altzone
    
    # 獲取時間,打印時間
    t = time.localtime()
    print(t)
    print("time.asctime(t) : %s" % time.asctime(t))
    
    # 延時    
    def my_sleep():
        time.sleep(3)
    
    # 計算sleep函數調用的時間時間
    t0 = time.clock()
    my_sleep()
    t1 = time.clock()
    print("function clock time : %d"
    % (t1 - t0)) t0 = time.time() my_sleep() t1 = time.time() print("sleep time %d" % (t1 - t0)) # 打印字符時間 print("time.ctime() : %s" % time.ctime())
  • 結果如下:

    技術分享圖片

Python time 的應用