zoukankan      html  css  js  c++  java
  • C#获取本周第一天和最后一天

                DateTime nowTime = DateTime.Now;
                #region 获取本周第一天
                //星期一为第一天  
                int weeknow = Convert.ToInt32(nowTime.DayOfWeek);
    
                //因为是以星期一为第一天,所以要判断weeknow等于0时,要向前推6天。  
                weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1));
                int daydiff = (-1) * weeknow;
    
                //本周第一天  
                DateTime FirstDay = nowTime.AddDays(daydiff);
           #endregion #region 获取本周最后一天 //星期天为最后一天 int lastWeekDay = Convert.ToInt32(nowTime.DayOfWeek); lastWeekDay = lastWeekDay == 0 ? (7 - lastWeekDay) : lastWeekDay; int lastWeekDiff = (7 - lastWeekDay); //本周最后一天 DateTime LastDay = nowTime.AddDays(lastWeekDiff);

           #endregion
  • 相关阅读:
    继承与多态
    本周总结
    总结
    周总结
    周总结
    第三周总结
    .......
    .....
    ....
    ....
  • 原文地址:https://www.cnblogs.com/shiliang199508/p/6490292.html
Copyright © 2011-2022 走看看