如何获得选择用C#.net一个月的最后一天? [英] How to get selected month's last date in C#.net?
问题描述
我使用一个下拉列表中的.aspx
页选择一个月。我得所选月的最后日期 .aspx.cs
页。 (有些月份有30天,有的31天)
I am using a drop down list for selecting the month in .aspx
page. I have to get last date of the selected month in .aspx.cs
page. (some months have 30 days and some have 31 days)
我怎样才能做到这一点?
How can I do this?
推荐答案
有没有需要自定义计算。
There's no need for custom calculations.
使用的<一个href=\"http://msdn.microsoft.com/en-us/library/system.datetime.daysinmonth.aspx\"><$c$c>System.DateTime.DaysInMonth(yearNum, monthNum) 方法找出(在任何一个月的天数这也是最后一天)。
Use the System.DateTime.DaysInMonth(yearNum, monthNum)
method to find out the number of days in any given month (which is also the last day).
这是简单:
//Get days in month 2 (Feb) of year 2011. Returns 28.
int daysInFeb2011 = System.DateTime.DaysInMonth(2011, 2);
MSDN文档提供了一个更彻底的描述性样本:
The MSDN documentation provides a more thorough and descriptive sample:
const int July = 7;
const int Feb = 2;
// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth(2001, July);
// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth(1998, Feb);
// daysInFebLeap gets 29 because the year 1996 was a leap year.
int daysInFebLeap = System.DateTime.DaysInMonth(1996, Feb);
这篇关于如何获得选择用C#.net一个月的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!