>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 5, 30, 15, 37, 12, 531883)
>>> print (datetime.datetime.now())#当前现在的时间
2018-05-30 15:37:35.631327
>>> print(datetime.datetime.now() + datetime.timedelta())#当前现在的时间
2018-05-30 15:38:52.390913
>>> print(datetime.datetime.now() + datetime.timedelta(3))#当前现在的时间+3天的时间
2018-06-02 15:38:58.598931
>>> print(datetime.datetime.now() + datetime.timedelta(hours=3))#当前现在的时间+3个小时的时间
2018-05-30 18:39:08.862841
>>> print(datetime.datetime.now() + datetime.timedelta(minutes=3))#当前现在的时间+3分钟的时间
2018-05-30 15:42:20.462443
>>> print(datetime.datetime.now() + datetime.timedelta(-3))#当前现在的时间-3天的时间
2018-05-27 15:39:31.558313
>>> c_time = datetime.datetime.now()
>>> c_time
datetime.datetime(2018, 5, 30, 15, 39, 52, 134712)
>>> print(c_time.replace(minute=3,hour=2))#当前现在的时间替换小时,分钟
2018-05-30 02:03:52.134712
>>> print(c_time)
2018-05-30 15:39:52.134712

posted on 2018-05-30 16:22  Linux的爱好者  阅读(123)  评论(0编辑  收藏  举报