CASE:输入某年某月某日,判断这一天是这一年的第几天?
# 输入某年某月某日, 判断这一天是这一年的第几天?
import datetime
dtstr = input('Enter the datetime:(20240124):')
dt = datetime.datetime.strptime(dtstr, "%Y%m%d")
another_dtstr = dtstr[:4] + '0101'
another_dt = datetime.datetime.strptime(another_dtstr, "%Y%m%d")
print(int((dt - another_dt).days) + 1)
标签:第几天,Python,Y%,程序,datetime,another,体验,dtstr,dt From: https://www.cnblogs.com/houhuilinblogs/p/17986118