时间模块,带Python示例
Python時(shí)間模塊 (Python time Module)
The time module is a built-in module in Python and it has various functions that require to perform more operations on time. This is one of the best modules in Python that used to solve various real-life time-related problems. To use the time module in the program, initially, we have to import the time module.
時(shí)間模塊是Python中的內(nèi)置模塊,它具有各種功能,需要按時(shí)執(zhí)行更多操作。 這是Python中最好的模塊之一,用于解決各種現(xiàn)實(shí)中與時(shí)間相關(guān)的問(wèn)題。 要在程序中使用時(shí)間模塊,首先,我們必須導(dǎo)入時(shí)間模塊 。
This module begins the recording time from the epoch. Epoch means time in history and it begins on 1st January 1970.
此模塊從紀(jì)元開(kāi)始記錄時(shí)間。 歷元是歷史上的時(shí)間,始于1970年1月1日。
時(shí)間模塊的一些重要功能 (Some important function of the time module)
1次() (1) time())
This function returns the number of the second count since the epoch.
此函數(shù)返回自紀(jì)元以來(lái)的第二個(gè)計(jì)數(shù)的編號(hào)。
Example:
例:
# Importing the module import times=time.time() print('Total seconds since epoch:',s)Output
輸出量
Total seconds since epoch: 1576083939.58772642)ctime() (2) ctime())
This function of the time module takes second as an argument and return time till the mentioned seconds.
時(shí)間模塊的此功能以秒為參數(shù),并返回時(shí)間直到提到的秒數(shù)。
Example:
例:
# Importing the module import times=1575293263.821702 Current_time=time.ctime(s) print('current time since epoch:',Current_time)Output
輸出量
current time since epoch: Mon Dec 2 13:27:43 20193)sleep() (3) sleep())
This function is used to stay the program execution for the time given in the arguments of this function.
該函數(shù)用于在該函數(shù)的參數(shù)中指定的時(shí)間內(nèi)保持程序執(zhí)行。
Example:
例:
# Importing the module import timeprint('Execution starting time:',time.ctime()) time.sleep(5) print('After execution time:',time.ctime())Output
輸出量
Execution starting time: Wed Dec 11 17:10:47 2019 After execution time: Wed Dec 11 17:10:52 20194)strftime() (4) strftime())
This function takes an argument and returns a string based on the format code.
該函數(shù)接受一個(gè)參數(shù),并根據(jù)格式代碼返回一個(gè)字符串。
Example:
例:
# Importing the module import timeCurrent_time=time.localtime() time_in_format=time.strftime("%m/%d/%Y, %H:%M:%S",Current_time)print('time in specific format since epoch:',time_in_format)Output
輸出量
time in specific format since epoch: 12/11/2019, 17:12:475)asctime() (5) asctime())
This function takes a tuple of length nine as an argument and returns a string.
此函數(shù)將長(zhǎng)度為9的元組作為參數(shù)并返回一個(gè)字符串。
Example:
例:
# Importing the module import timet=(2019,12,2,5,30,2,7,365,0) r=time.asctime(t) print("Time and date in a specific format:",r)Output
輸出量
Time and date in a specific format: Mon Dec 2 05:30:02 2019翻譯自: https://www.includehelp.com/python/time-module-with-example.aspx
總結(jié)
以上是生活随笔為你收集整理的时间模块,带Python示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 原神若雷结界怎么解除
- 下一篇: 延安多少钱啊?