[英]C# : How to get number of days from an object of DateTime
在C#中,如何查找駐留在DateTime對象中的一個月中的天數。
例如:
DateTime objDate=new DateTime();
使用objDate,現在我想獲得當月的天數。 在C#中是否存在任何內置函數?
閏年也必須得到照顧
int noOfDays = DateTime.DaysInMonth(objDate.Year, objDate.Month);
int days = DateTime.DaysInMonth(objDate.Year, objDate.Month);
int daysInMonth = System.DateTime.DaysInMonth(objDate.Year, objDate.Month);
這個怎么樣?
DateTime.DaysInMonth(date.Year, date.Month);
System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.CurrentUICulture;
Double DaysInMonth = cultureInfo.Calendar.GetDaysInMonth(DateTime.Now.Month, DateTime.Now.Year);
請嘗試以下方法:
DateTime objDate = default(DateTime);
objDate = Convert.ToDateTime("2009-02-05");
Response.Write(DateTime.DaysInMonth(objDate.Year, objDate.Month));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.