zoukankan      html  css  js  c++  java
  • 获取本周的周一日期与本周的周日日期

      #region 获取本周周一
            /// <summary>
            /// 获取本周的周一日期
            /// </summary>
            /// <returns></returns>
           public static string GetThisWeekMonday()  
            {  
                DateTime date = DateTime.Now;  
                DateTime firstDate = System.DateTime.Now;  
                switch (date.DayOfWeek)  
                {  
                    case System.DayOfWeek.Monday:  
                       firstDate = date;  
                       break;  
                   case System.DayOfWeek.Tuesday:  
                       firstDate = date.AddDays(-1);  
                       break;  
                   case System.DayOfWeek.Wednesday:  
                        firstDate = date.AddDays(-2);  
                       break;  
                   case System.DayOfWeek.Thursday:  
                        firstDate = date.AddDays(-3);  
                        break;  
                   case System.DayOfWeek.Friday:  
                       firstDate = date.AddDays(-4);  
                      break;  
                    case System.DayOfWeek.Saturday:  
                        firstDate = date.AddDays(-5);  
                        break;  
                   case System.DayOfWeek.Sunday:  
                       firstDate = date.AddDays(-6);  
                      break;  
              }
                return firstDate.ToString("yyyy-MM-dd");  
           }
            #endregion

            #region  获取本周的周日
          /// <summary>
           /// 获取本周的周日日期
          /// </summary>
          /// <returns></returns>
            public static string GetThisWeekSunday()  
           {  
                DateTime date = DateTime.Now;  
                DateTime lastDate = System.DateTime.Now;  
               switch (date.DayOfWeek)  
                {  
                    case System.DayOfWeek.Monday:  
                        lastDate = date.AddDays(6);  
                       break;  
                    case System.DayOfWeek.Tuesday:  
                        lastDate = date.AddDays(5);  
                       break;  
                    case System.DayOfWeek.Wednesday:  
                        lastDate = date.AddDays(4);  
                        break;  
                    case System.DayOfWeek.Thursday:  
                        lastDate = date.AddDays(3);  
                      break;  
                  case System.DayOfWeek.Friday:  
                       lastDate = date.AddDays(2);  
                        break;  
                   case System.DayOfWeek.Saturday:  
                        lastDate = date.AddDays(1);  
                        break;  
                    case System.DayOfWeek.Sunday:  
                        lastDate = date;  
                       break;  
               }  
              return lastDate.ToString("yyyy-MM-dd");
           }
           #endregion

  • 相关阅读:
    Magic-Club第六天
    .net工具类——文件操作
    .net工具类——HTML处理
    .net工具类——随机生成
    .net工具类——删除最后结尾的一个逗号
    .net工具类——分割字符串
    .net工具类——对象转换处理
    .net扩展方法——其他(科学计数法、ToDictionary 去重、List<Guid>转为List<Guid?>)
    .net扩展方法——类型转换
    『Linux学习笔记』7. 管道和过滤器 -- pipe
  • 原文地址:https://www.cnblogs.com/forthelichking/p/4730338.html
Copyright © 2011-2022 走看看