發布時間:2020-08-06 15:55 作者:獨孤劍 閱讀:1702
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { Console.WriteLine("本周最后一天:{0}", GetWeekLastDate(DateTime.Now)); Console.Read(); } /// <summary> /// 獲取本周最后一天(以星期天為最后一天) /// </summary> /// <param name="dateTime">當前時間 DateTime.Now or DateTime.UtcNow</param> /// <returns>后面的具體時、分、秒和傳入值相等</returns> public static DateTime GetWeekLastDate(DateTime dateTime) { int weeknow = Convert.ToInt32(dateTime.DayOfWeek); weeknow = (weeknow == 0 ? 7 : weeknow); int daydiff = (7 - weeknow); // 本周最后一天 return Convert.ToDateTime(dateTime.AddDays(daydiff)); } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞