Python时间模块 (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.

时间模块是Python中的内置模块,它具有各种功能,需要按时执行更多操作。 这是Python中最好的模块之一,用于解决各种现实中与时间相关的问题。 要在程序中使用时间模块,首先,我们必须导入时间模块

This module begins the recording time from the epoch. Epoch means time in history and it begins on 1st January 1970.

此模块从纪元开始记录时间。 历元是历史上的时间,始于1970年1月1日。

时间模块的一些重要功能 (Some important function of the time module)

1次() (1) time())

This function returns the number of the second count since the epoch.

此函数返回自纪元以来的第二个计数的编号。

Example:

例:

# Importing the module
import time
s=time.time()
print('Total seconds since epoch:',s)

Output

输出量

Total seconds since epoch: 1576083939.5877264

2)ctime() (2) ctime())

This function of the time module takes second as an argument and return time till the mentioned seconds.

时间模块的此功能以秒为参数,并返回时间直到提到的秒数。

Example:

例:

# Importing the module
import time
s=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 2019

3)sleep() (3) sleep())

This function is used to stay the program execution for the time given in the arguments of this function.

该函数用于在该函数的参数中指定的时间内保持程序执行。

Example:

例:

# Importing the module
import time
print('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 2019

4)strftime() (4) strftime())

This function takes an argument and returns a string based on the format code.

该函数接受一个参数,并根据格式代码返回一个字符串。

Example:

例:

# Importing the module
import time
Current_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:47

5)asctime() (5) asctime())

This function takes a tuple of length nine as an argument and returns a string.

此函数将长度为9的元组作为参数并返回一个字符串。

Example:

例:

# Importing the module
import time
t=(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

时间模块,带Python示例相关推荐

  1. python 全局_全局关键字,带Python示例

    python 全局 Python全局关键字 (Python global keyword) global is a keyword (case-sensitive) in python, it is ...

  2. python true_True关键字,带Python示例

    python true Python True关键字 (Python True keyword) True is a keyword (case-sensitive) in python, it is ...

  3. tau nb_math.tau常数,带Python示例

    tau nb Python math.tau常数 (Python math.tau constant) math.tau constant is a predefined constant, whic ...

  4. python none_None关键字,带Python示例

    python none Python None关键字 (Python None keyword) Note: None is not a keyword – we are just consideri ...

  5. python函数示例_带Python示例的complex()函数

    python函数示例 Python complex()函数 (Python complex() function) complex() function is a library function i ...

  6. python函数示例_带Python示例的float()函数

    python函数示例 Python float()函数 (Python float() function) float() function is a library function in Pyth ...

  7. spark 运行自带python示例的方式

    命令行直接执行: [root@master spark-2.2.0-bin-hadoop2.7]# bin/spark-submit examples/src/main/python/ml/kmean ...

  8. python中calendar怎么用_Python时间模块datetime、time、calendar的使用方法

    import time import datetime #两日期相减 d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, ...

  9. python time localtimeq获取准确时间_Python时间模块datetime、time、calendar的使用方法

    本文简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用,希望这篇文章对于学习Python的朋友们有所帮助. 首先就是模块的调用,很多 ...

最新文章

  1. innodb_monitor
  2. LibreOJ #6002. 「网络流 24 题」最小路径覆盖
  3. 洛谷 P2261 [CQOI2007]余数求和
  4. Github标星59.7k:用动画的形式呈现解LeetCode题目的思路
  5. Spring、SpringBoot常见面试题与答案
  6. python安装成功的图标_安装Python
  7. 吴恩达机器学习(七)神经网络(反向传播)
  8. WINDOWS平台上扩展SGA,把你的内存用起来吧
  9. 考场自动安排工具开发手记
  10. Iris数据集可视化
  11. A64的原装风扇真让人头痛
  12. 下载加速小妙招,我不允许你不知道
  13. Blogspot.com再次解封
  14. 袁萌记忆中的华罗庚先生
  15. python调用rarfile进行解压rar压缩包时,报了如下错误
  16. linux系统top命令:virt,res,shr详解
  17. 安全多方计算技术及其在阿里巴巴的应用
  18. 软件测试显卡最高清晰度,FF14各种显卡测试,GTX 750以上就能开启最高画质
  19. C语言七巧板游戏制作,七巧板具体玩法与制作方法详解
  20. 使用nginx配置一个ip对应多个域名

热门文章

  1. 浅谈大前端的代表技术及其影响,值得我们思考
  2. moment 24小时与12小时区别
  3. Odyssey.js – 使用现成模板在线创建互动的故事
  4. ie下按keydown事件会触发button
  5. SASS简介及使用方法
  6. mpvue tabBar设定 app.json
  7. VM克隆之后启动eth0找不到eth0:unknown interface:no such device
  8. data URI scheme及其应用
  9. POJ3185(简单BFS,主要做测试使用)
  10. 为什么要使用反射机制