python enter certain date, to determine which is the first few days of the year? (you can use Python's built-in module)

import datetime

y = int(input('请输入4位数字的年份:'))  # 获取年份
m = int(input('请输入月份:'))  # 获取月份
d = int(input('请输入是哪一天:'))  # 获取“日”

targetDay = datetime.date(y, m, d)  # 将输入的日期格式化成标准的日期
dayCount = targetDay - datetime.date(targetDay.year - 1, 12, 31)  # 减去上一年最后一天
print('%s是%s年的第%s天。' % (targetDay, y, dayCount.days))
import time
y = int(input('请输入4位数字的年份:'))  # 获取年份
m = int(input('请输入月份:'))  # 获取月份
d = int(input('请输入是哪一天:'))  # 获取“日”

print(time.strptime(f'{y}-{m}-{d}', '%Y-%m-%d').tm_yday)

Guess you like

Origin www.cnblogs.com/bladecheng/p/11545115.html