• 根据当期时间得到本周第一天和最后一天


    /// <summary>
            /// 根据指定接收本周第一天和最后一天
            /// </summary>
            /// <param name="day">当前日期</param>
            /// <param name="sDate">本周第一天</param>
            /// <param name="eDate">本周最后一天</param>
            public static void GetWeekStarAndEnd(DateTime day, out DateTime sDate, out DateTime eDate)
            {
            
                sDate = DateTime.MinValue;
                eDate = DateTime.MinValue;
                switch (day.DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        sDate = Convert.ToDateTime(day.ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Tuesday:
                        sDate = Convert.ToDateTime(day.AddDays(-1).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Wednesday:
                        sDate = Convert.ToDateTime(day.AddDays(-2).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Thursday:
                        sDate = Convert.ToDateTime(day.AddDays(-3).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Friday:
                        sDate = Convert.ToDateTime(day.AddDays(-4).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Saturday:
                        sDate = Convert.ToDateTime(day.AddDays(-5).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                    case DayOfWeek.Sunday:
                        sDate = Convert.ToDateTime(day.AddDays(-6).ToString("yyyy-MM-dd"));
                        eDate = new DateTime(sDate.Year, sDate.AddDays(6).Month, sDate.AddDays(6).Day, 23, 59, 59);
                        break;
                }
            }

            /// <summary>
            /// 根据指定时间计算旬起始日期
            /// </summary>
            /// <param name="day">当前日期</param>
            /// <param name="sDate">旬开始日期</param>
            /// <param name="eDate">旬结束日期</param>
            /// <returns>返回旬(上旬,中旬,下旬)</returns>
            public static string Xun(DateTime day, out DateTime sDate, out DateTime eDate)
            {
                string ss = "";
                sDate = DateTime.MinValue;
                eDate = DateTime.MinValue;

                if (day.Day > 0 && day.Day < 11)
                {
                    sDate = new DateTime(day.Year, day.Month, 1);
                    eDate = new DateTime(day.Year, day.Month, 10, 23, 59, 59);
                    ss = "上旬";
                }

                if (day.Day > 10 && day.Day < 21)
                {
                    sDate = new DateTime(day.Year, day.Month, 11);
                    eDate = new DateTime(day.Year, day.Month, 20, 23, 59, 59);
                    ss = "中旬";
                }

                if (day.Day > 20 && day.Day <= 31)
                {
                    sDate = new DateTime(day.Year, day.Month, 21);
                    eDate = new DateTime(day.Year, day.Month, Convert.ToDateTime(day.AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1).Day, 23, 59, 59);

                    ss = "下旬";
                }

                return ss;
            }

            /// <summary>
            /// 计算季度
            /// </summary>
            /// <param name="day">当前日期</param>
            /// <param name="sDate">季度开始日期</param>
            /// <param name="eDate">季度结束日期</param>
            /// <returns>季度日期</returns>
            public static string JiDu(DateTime day, out DateTime sDate, out DateTime eDate)
            {
                string ss = "";

                sDate = DateTime.MinValue;
                eDate = DateTime.MinValue;

                if (day.Month > 0 && day.Month < 4)
                {
                    sDate = new DateTime(day.Year, 1, 1);
                    ss = "第一季度";
                }

                if (day.Month > 3 && day.Month < 7)
                {
                    sDate = new DateTime(day.Year, 4, 1);
                    ss = "第二季度";
                }

                if (day.Month > 7 && day.Month < 10)
                {
                    sDate = new DateTime(day.Year, 7, 1);
                    ss = "第三季度";
                }

                if (day.Month > 10 && day.Month <= 12)
                {
                    sDate = new DateTime(day.Year, 10, 1);
                    ss = "第四季度";
                }

                eDate = Convert.ToDateTime(sDate.AddMonths(3).ToString("yyyy-MM-01")).AddDays(-1);

                return ss;
            }

  • 相关阅读:
    四个通用分页存储过程(来源于www.codeproject.com)
    C#2.0 print winform 打印窗体数据试试
    C# 2.0 Graphics 画雪人
    [转]Asp.Net 上传大文件专题(1)概述:上传大文件的难点
    [转]Asp.Net 上传大文件专题(2)页面生成流程
    [转]C# 调用sql 2000存储过程
    [转]Asp.Net 上传大文件专题
    [转]Asp.Net 上传大文件专题(3)从请求流中获取数据并保存为文件[下]
    c#中调用Ffmpeg转换视频格式的问题
    [转]Asp.Net 上传大文件专题(3)从请求流中获取数据并保存为文件[上]
  • 原文地址:https://www.cnblogs.com/dachuang/p/4899932.html
Copyright © 2020-2023  润新知