将“月/年”转换为月中的天数-Python日期时间

时间:2020-01-09 17:28:24

标签: python datetime

如何将月/日/年11/1/2018转换为代表该年中给定月份中天数的值?转换值应为30,因为2018年11月有30天。

我唯一能想到的就是做一些基于规则的逻辑,如下所示。是否有一个python模块可以帮助解决这个问题?

print("List of months: January, February, March, April, May, June, July, August, September, October, November, December")
month_name = input("Input the name of Month: ")

if month_name == "February":
    print("No. of days: 28/29 days")
elif month_name in ("April", "June", "September", "November"):
    print("No. of days: 30 days")
elif month_name in ("January", "March", "May", "July", "August", "October", "December"):
    print("No. of days: 31 day")
else:
    print("Wrong month name") 

下面还有excel中的“每月的日子”通用论坛:

=DAY(EOMONTH(date,0)) 

但是这需要在python中。谢谢。

0 个答案:

没有答案