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

python学习-46 时间模块

时间:2019-07-28 15:26:34      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:mon   oca   imp   color   标准   ctime   sleep   pre   time   

时间模块

 

····时间戳

print(time.time())

运行结果:

1 1564294158.0389376
2 
3 Process finished with exit code 0

 

 

 

·····结构化时间

print(time.localtime())         # 当地时间
y = time.localtime()
print(y.tm_year)
print(y.tm_wday)

print(time.gmtime()) # 世界标准化时间 UTC

运行结果:

time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=14, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0)
2019
6
time.struct_time(tm_year=2019, tm_mon=7, tm_mday=28, tm_hour=6, tm_min=25, tm_sec=57, tm_wday=6, tm_yday=209, tm_isdst=0)

Process finished with exit code 0

 

 

 

·····结构化时间转换成时间戳

print(time.mktime(time.localtime()))

 

 

``````结构化时间转换成字符串时间

print(time.strftime(%Y-%m-%d %X,time.localtime()))

运行结果:

2019-07-28 14:34:58

Process finished with exit code 0

 

 

 

``````字符串时间转换成结构化时间

print(time.strptime(2018:1:1:12:00:00,%Y:%m:%d:%X))

运行结果:

time.struct_time(tm_year=2018, tm_mon=1, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=1, tm_isdst=-1)

Process finished with exit code 0

 

 

······把结构化时间转换成固定的字符串表达形式

print(time.asctime())
print(time.ctime())

运行结果:

Sun Jul 28 14:43:45 2019
Sun Jul 28 14:43:45 2019

Process finished with exit code 0

 

 

····推迟运行

print(time.sleep(1))

 

 

ps:

import datetime模块


print(datetime.datetime.now())

 

python学习-46 时间模块

标签:mon   oca   imp   color   标准   ctime   sleep   pre   time   

原文地址:https://www.cnblogs.com/liujinjing521/p/11258973.html

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