python的时间模块
from datetime import datetime#导入模块里面的当前时间模块
import time
print(dir(datetime))
now_time = datetime.now()#获得当前的时间
print("now:{0}".format(now_time))
print('now day:{0}'.format(now_time.date()))#将时间格式化
print('now day:{0}'.format(now_time.time()))
print('now day:{0}'.format(now_time.today()))
print('now day:{0}'.format(now_time.year))
print('now day:{0}'.format(now_time.month ))
print(dir(now_time))
print(time.time())
print("--------------------------------------------------")
#自定义时间输出
d= datetime(2020,10,30,14,6)
#时间日期字符串之间的转换
ds = '2018/10/3'
ds_t=datetime.strptime(ds,'%Y/%m/%d')
print(ds_t)
print("---------------------------------------------------")
n=datetime.now()
print(n)
n_str = n.strftime('%Y/%m/%d%H:%M:%S')#转换为字符串
print(n_str)
print(type(n_str))
print("----------------------------------------------------")
#datetime之间的加减操作
n = datetime.now()
n_next =n + timedelta (days=5,hours=42,minutes=4)
新闻标题:python的时间模块
分享路径:http://ybzwz.com/article/gpdpcd.html