C#获得某年某月的起止日期方法其实很简单,我们来看看下面的例子:
//得到某年某月的起止日期,格式为yyyy-mm-dd public static string[] GetBeginEndDate(int rYear,int rMonth) { string[] arr = new string[2]; DateTime dt1 = DateTime.Parse(rYear+"-"+rMonth+"-01"); arr[0] = dt1.ToLongDateString(); DateTime dt2 = dt1.AddMonths(1).AddDays(-1); arr[1] = dt2.ToLongDateString(); return arr; }
基础知识
DateTime.Parse方法
将日期和时间的字符串表示形式转换为其等效的 DateTime。
public static DateTime Parse (string s);
参数
s String
包含要转换的日期和时间的字符串。
返回 DateTime
一个对象,它等效于 s 中包含的日期和时间。
DateTime.ToLongDateString 方法
将当前 DateTime 对象的值转换为其等效的长日期字符串表示形式。
public string ToLongDateString ();
返回 String
一个字符串,它包含当前 DateTime 对象的长日期字符串表示形式。
通过以上内容我们知道了C#获得某年某月的起止日期方法,感谢您访问“我爱捣鼓(www.woaidaogu.com)”网站的内容,希望对大家有所帮助!引用本文内容时,请注明出处!谢谢合作!