datetime模块


Python从入门到放弃完整教程目录:https://www.cnblogs.com/nickchen121/p/10718112.html

一、datetime模块

# datetime模块可以看成是时间加减的模块
import datetime
# 返回当前时间
print(datetime.datetime.now())
2019-03-07 16:22:14.544130
print(datetime.date.fromtimestamp(time.time()))
2019-03-07
# 当前时间+3天
print(datetime.datetime.now() + datetime.timedelta(3))
2019-03-10 16:22:14.560599
# 当前时间-3天
print(datetime.datetime.now() + datetime.timedelta(-3))
2019-03-04 16:22:14.568473
# 当前时间-3小时
print(datetime.datetime.now() + datetime.timedelta(hours=3))
2019-03-07 19:22:14.575881
# 当前时间+30分钟
print(datetime.datetime.now() + datetime.timedelta(minutes=30))
2019-03-07 16:52:14.585432
# 时间替换
c_time = datetime.datetime.now()
print(c_time.replace(minute=20, hour=5, second=13))
2019-03-07 05:20:13.595493
posted @ 2019-05-04 09:30  B站-水论文的程序猿  阅读(1655)  评论(1编辑  收藏  举报