计算一个月中的天数 [英] no of days in a month calculation
本文介绍了计算一个月中的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个下拉列表年份和月份.
当我选择了月份和年份时..获取一个月中的天数..in c Sharp.
请回复我
i have two dropdownlist year and month..
when i have select the month and year..getthe no of days in a month ....in c sharp.
pls reply me
推荐答案
尝试一下.. :)
try this.. :)
int days = DateTime.DaysInMonth(int Year,int Month);
您可以在Integer
中写年和月
E.G.
where you can write Year and month in Integer
E.G.
int days = DateTime.DaysInMonth(2014,2);
这将返回28天
This will return 28 Days
您可以为此使用javascript
You can use javascript for this
function daysInMonth(month,year)
{
return new Date(year, month, 0).getDate();
}
如果您希望使用c sharp完成此操作,请使用Ajax或在放下change事件时调用以下方法.
If you want it to be done using c sharp ,call the below method using Ajax or on drop down change event.
public int GetDays(int year, int month){
return DateTime.DaysInMonth(year, month);
}
这篇关于计算一个月中的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文