Python Note 500 - Datetime
Python 标准库中的 datetime 模块提供了各种对日期和时间的处理方法。 基本操作 In [1]: import datetime In [2]: now = datetime.datetime.now() In [3]: now Out[3]: datetime.datetime(2015, 6, 1, 10, 26, 38, 836099) 时间转换为字符串 In [4]: now.strftime("%Y-%m-%d %H:%M:%S") Out[4]: '2015-06-01 10:26:38' In [5]: now.replace(hour=0,minute=0,second=0) Out[5]: datetime.datetime(2015, 6, 1, 0, 0, 0, 836099) In [6]: now - datetime.timedelta(days=1) Out[6]: datetime.datetime(2015, 5, 31, 10, 26, 38, 836099) 字符串转换为时间 In [7]: str = 'Fri, 19 May 2017 10:50:42' In [8]: datetime.datetime.strptime(str, '%a, %d %b %Y %H:%M:%S') Out[8]: datetime....