描述
方法time()以自紀元以來的秒數表示的浮點數返回時間,以 UTC 為單位。
注意- 盡管時間總是作為浮點數返回,但並非所有係統都提供比 1 秒更好的時間精度。雖然此函數通常返回非遞減值,但如果係統時鍾在兩次調用之間已回退,則它可以返回比前一次調用低的值。
用法
以下是語法time()方法≫
time.time()
參數
NA
返回值
此方法以浮點數形式返回時間,以自紀元以來的秒數表示,以 UTC 為單位。
示例
下麵的例子展示了 time() 方法的用法。
#!/usr/bin/python3
import time
print ("time.time():%f " % time.time())
print (time.localtime( time.time() ))
print (time.asctime( time.localtime(time.time()) ))
結果
當我們運行上麵的程序時,它會產生以下結果——
time.time():1455519806.011433 time.struct_time(tm_year = 2016, tm_mon = 2, tm_mday = 15, tm_hour = 12, tm_min = 33, tm_sec = 26, tm_wday = 0, tm_yday = 46, tm_isdst = 0) Mon Feb 15 12:33:26 2016
相關用法
- Python 3 time tzset()用法及代碼示例
- Python 3 time strftime()用法及代碼示例
- Python 3 time asctime()用法及代碼示例
- Python 3 time altzone()用法及代碼示例
- Python 3 time localtime()用法及代碼示例
- Python 3 time mktime()用法及代碼示例
- Python 3 time gmtime()用法及代碼示例
- Python 3 time sleep()用法及代碼示例
- Python 3 time ctime()用法及代碼示例
- Python 3 time strptime()用法及代碼示例
- Python 3 time clock()用法及代碼示例
- Python 3 Number tan()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 List pop()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 dictionary cmp()用法及代碼示例
- Python 3 String isupper()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 List index()用法及代碼示例
- Python 3 String decode()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - time time() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。