時間差天數 #!/usr/bin/python3 #coding=utf-8 import time import datetime d1 = datetime.datetime(2018, 10, 18) d2 = datetime.datetime(2017, 12, 31) print ( (d1 - d2).days) ## 當前日期 curdate = datetime.date.today() print ("curdate = ", curdate) 結果: 291 curdate = 2018-09-12 -------------------------------------------------------------------------------- 時間差秒數 import datetime import time t = (datetime.datetime(2019,1,13,12,0,0) - datetime.datetime.now()).total_seconds() print ("t = ", t) 結果: t = 10590173.903113 ---------------------------------------------------------------------------------------- 時間間隔 時間間隔是以秒為單位的浮點數。 從1970年1月1日上午12:00(epoch),這是一種時間的特殊時刻表示。在Python中,當前時刻與上述特殊的某個時間點之間以秒為單位的時間。這個時間段叫做Ticks。 # Import time module. import time; # Seconds ticks = time.time() print ("Number of ticks since 12:00am, January 1, 1970: ", ticks) #結果:Number of ticks since 12:00am, January 1, 1970: 1536791008.3215983 ---------------------------------------------------------------------------------------- 分享知識,分享快樂!希望中國站在編程之巔!
|
|