显示日期 [英] Display Date
本文介绍了显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ASP.NET中显示基于年份(考虑leap年)的月份的最后日期
how to display the last date of the month based on the year (taking into account leap year)in ASP.NET
推荐答案
让.Net处理此问题您:
Let .Net handle this for you:
public DateTime LastDayOfMonthFromDateTime(DateTime dateTime)
{
DateTime firstDayOfTheMonth = new DateTime(dateTime.Year, dateTime.Month, 1);
return firstDayOfTheMonth.AddMonths(1).AddDays(-1);
}
public int GetDaysInMonth(int month, int year)
{
DateTime date = DateTime.Now;
if (month == 12) date = new DateTime(year + 1, 1, 1);
else date = new DateTime(year, month + 1, 1);
return date.AddDays(-1).Day;
}
这篇关于显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文