time和datetime傻傻搞不清楚
数据转换为日期的方法,作为日期存在电子表格中,只能用
datetime.date.today() 或
datetime.datetime.strptime(a, '%Y%m%d').date()
,才能存为日期格式的数据
import time
import datetime
a = '20181114'
print(time.strptime(a, '%Y%m%d'))
print(time.strptime(a, '%Y%m%d').tm_year)
print(type(time.strptime(a, '%Y%m%d').tm_year))
print('================')
print(time.localtime())
print(time.strftime('%Y-%m-%d', time.localtime()))
print(time.strftime('%Y-%m-%d', time.strptime(a, '%Y%m%d')))
print(type(time.strftime('%Y-%m-%d', time.strptime(a, '%Y%m%d'))))
print('================')
print(datetime.datetime.strptime(a, '%Y%m%d'))
print(datetime.datetime.strptime(a, '%Y%m%d').date())
print(type(datetime.datetime.strptime(a, '%Y%m%d').date()))
print('================')
print(datetime.datetime.now().strftime('%Y-%m-%d'))
print(datetime.date.today())
print(type(datetime.date.today()))
import datetime
res = '20190621'
date = datetime.datetime.strptime(res, "%Y%m%d").date()
# 求当前的日期是一年中的第几周
print(date.strftime("%W"))
# 25
# 求当前的日期是一周中的周几
print(date.strftime("%w"))
# 5