【发布时间】:2019-11-29 09:15:26
【问题描述】:
如何从string 中提取DateTime 戳格式的月份和年份?
sales_close_7 = 2018-12-07
【问题讨论】:
-
我需要日期时间格式而不是字符串
标签: python-3.x python-datetime
如何从string 中提取DateTime 戳格式的月份和年份?
sales_close_7 = 2018-12-07
【问题讨论】:
标签: python-3.x python-datetime
import datetime
sales_close_7 = '2018-12-07'
date_object = datetime.datetime.strptime(sales_close_7, '%Y-%m-%d').date()
print(date_object.year)
Output: 2018
print(date_object.month)
Output: 12
【讨论】: