|
/// <summary>
/// 得到本月的第一天日期
/// </summary>
/// <returns>DateTime</returns>
public static DateTime GetFirstDayOfMonth()
{
return GetFirstDayOfMonth(DateTime.Now);
}
/// <summary>
/// 得到本月的最有一天的日期
/// </summary>
/// <returns>DateTime</returns>
public static DateTime GetLastDayOfMonth()
{
return GetLastDayOfMonth(DateTime.Now);
}
/// <summary>
/// 得到一個月的第一天
/// </summary>
/// <param name="someday">這個月的隨便一天</param>
/// <returns>DateTime</returns>
public static DateTime GetFirstDayOfMonth(DateTime someday)
{
int totalDays = DateTime.DaysInMonth(someday.Year, someday.Month);
DateTime result;
int ts = 1 - someday.Day;
result = someday.AddDays(ts);
return result;
}
/// <summary>
/// 得到一個月的最后一天
/// </summary>
/// <param name="someday">這個月的隨便一天</param>
/// <returns>DateTime</returns>
public static DateTime GetLastDayOfMonth(DateTime someday)
{
int totalDays = DateTime.DaysInMonth(someday.Year, someday.Month);
DateTime result;
int ts = totalDays - someday.Day;
result = someday.AddDays(ts);
return result;
}
#endregion
AspNet技術:asp.net 日期函數 某月的第一天和最后一天的日期,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。