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

  • 相关阅读:
    PowerShell_零基础自学课程_7_Powershell中重定向机制、目录和文件管理
    volcanol_C语言学习趣事汇总贴
    linux_shell_2_shell 中的变量特性
    PowerShell_零基础自学课程_5_自定义PowerShell环境及Powershell中的基本概念
    volcanol_Linux_问题汇总系列_2_如何在linux和windows主机之间共享文件
    C语言学习趣事_你不知道的C语言应用
    volcanol_Windows_Powershell_汇总贴
    PowerShell_零基础自学课程_4_PowerShell的别名功能、错误管理功能和系统资源区域导航
    Sqlite 管理工具 SQLiteDeveloper及破解
    android建立Menu详解
  • 原文地址:https://www.cnblogs.com/Jack_G/p/2314149.html
Copyright © 2011-2022 走看看