加入时间因素

在 Python 中处理日期和时间

Max Shron

Data Scientist and Author

日期与时间

在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(2017, 10, 1
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(2017, 10, 1, 15
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(2017, 10, 1, 15, 23, 
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(2017, 10, 1, 15, 23, 25)
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(2017, 10, 1, 15, 23, 25, 500000)
在 Python 中处理日期和时间

日期与时间

# Import datetime
from datetime import datetime

dt = datetime(year=2017, month=10, day=1, 
              hour=15, minute=23, second=25, 
              microsecond=500000)
在 Python 中处理日期和时间

替换 datetime 的部分字段

print(dt)
2017-10-01 15:23:25.500000
dt_hr = dt.replace(minute=0, second=0, microsecond=0)
print(dt_hr)
2017-10-01 15:00:00
在 Python 中处理日期和时间

Capital Bikeshare

在 Python 中处理日期和时间

加入时间因素

在 Python 中处理日期和时间

Preparing Video For Download...