发布时间:2019-09-11 07:46:27编辑:auto阅读(1654)
1.time的使用
import time
print(time.time())#打印当前时间戳
print(time.localtime())#打印当前时间元组
print(time.asctime(time.localtime()))#打印内置时间格式
print(time.strftime('%Y-%m-%d',time.localtime()))#将时间元组转变为字符串
print(time.strptime('2018-06-15','%Y-%m-%d'))#将字符串转转换为时间元组
print(time.mktime(time.strptime('2018-06-15','%Y-%m-%d')))#将时间元组转变为时间戳
>>:
1529034110.4935222
time.struct_time(tm_year=2018, tm_mon=6, tm_mday=15, tm_hour=11, tm_min=41, tm_sec=50, tm_wday=4, tm_yday=166, tm_isdst=0)
Fri Jun 15 11:41:50 2018
2018-06-15
time.struct_time(tm_year=2018, tm_mon=6, tm_mday=15, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=166, tm_isdst=-1)
1528992000.0
2.datetimede的使用
import datetime
print(datetime.datetime.now())#打印当前时间
print(datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d'))#打印日期格式化字符串
#日期运算
print(datetime.datetime.now()+datetime.timedelta(days=2))
>>:
2018-06-15 11:41:50.495522
2018-06-15
2018-06-17 11:41:50.495522
上一篇: python的vim的简单设置
下一篇: python之exec,eval,exe
47848
46403
37291
34738
29321
25977
24923
19955
19549
18033
5798°
6421°
5936°
5965°
7071°
5920°
5950°
6446°
6408°
7787°