Answers:
您将在该月的最后一天返回31:
DateTime.DaysInMonth(1980, 08);
从 DateTimePicker:
第一次约会:
DateTime first_date = new DateTime(DateTimePicker.Value.Year, DateTimePicker.Value.Month, 1);
最后日期:
DateTime last_date = new DateTime(DateTimePicker.Value.Year, DateTimePicker.Value.Month, DateTime.DaysInMonth(DateTimePicker.Value.Year, DateTimePicker.Value.Month));
要获取特定日历中的一个月的最后一天-以及扩展方法-:
public static int DaysInMonthBy(this DateTime src, Calendar calendar)
{
var year = calendar.GetYear(src); // year of src in your calendar
var month = calendar.GetMonth(src); // month of src in your calendar
var lastDay = calendar.GetDaysInMonth(year, month); // days in month means last day of that month in your calendar
return lastDay;
}
// Use any date you want, for the purpose of this example we use 1980-08-03.
var myDate = new DateTime(1980,8,3);
var lastDayOfMonth = new DateTime(myDate.Year, myDate.Month, DateTime.DaysInMonth(myDate.Year, myDate.Month));
var myDate = new DateTime(1980, 1, 31);
(返回29日)
我不了解C#,但是,事实证明,没有一种便捷的API方式来获取它,您可以通过以下逻辑来做到这一点:
today -> +1 month -> set day of month to 1 -> -1 day
当然,这假设您具有该类型的日期数学。