【python】获取当前年份和月份以及获取当前时间(年月日时分秒)

获取当前年份和月份

import datetime
today = datetime.datetime.today()
year = today.year
month = today.month

获取当前时间(年月日时分秒)

now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

你可能感兴趣的:(python,python)