码迷,mamicode.com
首页 > 编程语言 > 详细

python的time模块

时间:2018-05-28 13:40:28      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:localtime   单位   运行   fse   rom   lock   val   imp   strftime   

 1 #encoding=utf-8
 2 import time
 3 
 4 # 返回时间戳
 5 print time.time()
 6 
 7 # 延迟运行单位为s,如下为延迟3s
 8 time.sleep(3)
 9 
10 # 转换时间戳为时间元组(时间对象),自1970+second,其second为秒数
11 print time.gmtime(4)
12 
13 # 转换时间戳为本地对象
14 print time.localtime()
15 
16 # 将时间戳转换为字符串
17 print time.asctime(time.localtime())
18 
19 # 将时间戳转换为字符串
20 print time.ctime(5)
21 
22 # 将本地时间转换为时间戳
23 t = (2009, 2, 17, 17, 3, 38, 1, 48, 0)
24 print time.mktime(t)
25 
26 # 将时间对象转换为规范性字符串(常用),格式如下
27 ‘‘‘
28 %Y Year with century as a decimal number.
29 %m Month as a decimal number [01,12].
30 %d Day of the month as a decimal number [01,31].
31 %H Hour (24-hour clock) as a decimal number [00,23].
32 %M Minute as a decimal number [00,59].
33 %S Second as a decimal number [00,61].
34 %z Time zone offset from UTC.
35 %a Locale‘s abbreviated weekday name.
36 %A Locale‘s full weekday name.
37 %b Locale‘s abbreviated month name.
38 %B Locale‘s full month name.
39 %c Locale‘s appropriate date and time representation.
40 %I Hour (12-hour clock) as a decimal number [01,12].
41 %p Locale‘s equivalent of either AM or PM.
42 ‘‘‘
43 print time.strftime(%Y-%m-%d %H-%M-%S,t)
44 
45 # 将时间字符串根据指定的格式化符转换成数组形式的时间
46 struct_time = time.strptime("30 Nov 00", "%d %b %y")
47 print struct_time

 

python的time模块

标签:localtime   单位   运行   fse   rom   lock   val   imp   strftime   

原文地址:https://www.cnblogs.com/cmnz/p/9099564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!