【Python】Python 日期时间操作包 - datetime

Backto Python Index

import datetime
# make datetime from string
start_time = datetime.datetime.strptime("2019-08-20 14:35:25", '%Y-%m-%d %H:%M:%S')
# datetime to string and print
print(start_time.strftime('%Y-%m-%d %H:%M:%S'))
# change datetime with given delta
start_time = start_time + datetime.timedelta(seconds=1)
print(start_time.strftime('%Y-%m-%d %H:%M:%S'))
  • 格式符对应关系

你可能感兴趣的:(Python)