• 获取本周的周一和周日


    代码
            // 获取本周的周一
            public string GetThisWeekMonday()
            {
                DateTime date 
    = DateTime.Now;
                DateTime first 
    = System.DateTime.Now;
                
    switch (date.DayOfWeek)
                {
                    
    case System.DayOfWeek.Monday:
                        first 
    = date;
                        
    break;
                    
    case System.DayOfWeek.Tuesday:
                        first 
    = date.AddDays(-1);
                        
    break;
                    
    case System.DayOfWeek.Wednesday:
                        first 
    = date.AddDays(-2);
                        
    break;
                    
    case System.DayOfWeek.Thursday:
                        first 
    = date.AddDays(-3);
                        
    break;
                    
    case System.DayOfWeek.Friday:
                        first 
    = date.AddDays(-4);
                        
    break;
                    
    case System.DayOfWeek.Saturday:
                        first 
    = date.AddDays(-5);
                        
    break;
                    
    case System.DayOfWeek.Sunday:
                        first 
    = date.AddDays(-6);
                        
    break;
                }
                
    return first.ToString("yyyy-MM-dd");
            }


            
    // 获取本周的周日
            public string GetThisWeekSunday()
            {
                DateTime date 
    = DateTime.Now;
                DateTime last 
    = System.DateTime.Now;
                
    switch (date.DayOfWeek)
                {
                    
    case System.DayOfWeek.Monday:
                        last 
    = date.AddDays(6);
                        
    break;
                    
    case System.DayOfWeek.Tuesday:
                        last 
    = date.AddDays(5);
                        
    break;
                    
    case System.DayOfWeek.Wednesday:
                        last 
    = date.AddDays(4);
                        
    break;
                    
    case System.DayOfWeek.Thursday:
                        last 
    = date.AddDays(3);
                        
    break;
                    
    case System.DayOfWeek.Friday:
                        last 
    = date.AddDays(2);
                        
    break;
                    
    case System.DayOfWeek.Saturday:
                        last 
    = date.AddDays(1);
                        
    break;
                    
    case System.DayOfWeek.Sunday:
                        last 
    = date;
                        
    break;
                }
                
    return last.ToString("yyyy-MM-dd");
            }
    撸码:复制、粘贴,拿起键盘就是“干”!!!
  • 相关阅读:
    WPF解析Fnt字体
    WPF九宫格HLSL版
    BitmapSource ConvertTo Bitmap
    避免重复注册事件引起的内存泄漏
    拆解凹多边形
    轮廓检测
    主动模式FTP与被动模式FTP该如何选择
    深入浅出 消息队列 ActiveMQ
    ftp 文件读取和解析入库
    mysql存储过程语法及实例
  • 原文地址:https://www.cnblogs.com/niunan/p/1829133.html
Copyright © 2020-2023  润新知