Anesthesia-is

python中datatime模块的使用方法

导入包 import datetime

获取当天日期 now_time=datetime.datetime.now()

print((now_time+datetime.timedelta(days=+1)).strftime("%Y-%m-%d %H:%M:%S")) #获取后一天+1  前一天-1

print ((now_time+datetime.timedelta(hours=-1)).strftime("%Y-%m-%d %H:%M:%S")) #获取前一小时

print(now_time.strftime("%Y-%m-%d %H:%M:%S"),(now_time+datetime.timedelta(minutes=+1)).strftime("%Y-%m-%d %H:%M:%S"))   #前一分钟后一分钟

print(now_time.strftime("%Y-%m-%d %H:%M:%S"),(now_time+datetime.timedelta(minutes=+1/60)).strftime("%Y-%m-%d %H:%M:%S"))#前一秒后一秒

分类:

技术点:

相关文章: