zoukankan      html  css  js  c++  java
  • 得到时间段内周末的天数

     1         /// <summary>
     2         /// 得到一个时间段内周末的天数
     3         /// </summary>
     4         /// <param name="stDate">开始时间</param>
     5         /// <param name="endDate">结束时间</param>
     6         /// <returns></returns>
     7         public double GetWeekEndTotalDays(DateTime stDate,DateTime endDate)
     8         {
     9             double weekEndCount = 0.000;
    10 
    11             if (endDate.Date.ToString() == stDate.Date.ToString() &&
    12                 (stDate.DayOfWeek.ToString() == "Saturday" || stDate.DayOfWeek.ToString() == "Sunday"))
    13             {
    14                 weekEndCount += (endDate - stDate).TotalDays;
    15                 return weekEndCount;
    16             }
    17 
    18             //计算不在活动范围内的周末的天数
    19             if (stDate.DayOfWeek.ToString() == "Saturday" || stDate.DayOfWeek.ToString() == "Sunday")
    20                 weekEndCount += (stDate.AddDays(1).Date - stDate).TotalDays;
    21             stDate = stDate.AddDays(1).Date;
    22             if (endDate.DayOfWeek.ToString() == "Saturday" || endDate.DayOfWeek.ToString() == "Sunday")
    23                 weekEndCount += (endDate - endDate.AddDays(-1).Date).TotalDays;
    24             endDate = endDate.AddDays(-1).Date;
    26 
    27             TimeSpan tsWeekEnd = endDate - stDate;
    28             for (int j = 0; j <= tsWeekEnd.Days; j++)
    29             {
    30                 if (stDate.DayOfWeek.ToString() == "Saturday" || stDate.DayOfWeek.ToString() == "Sunday")
    31                 {
    32                     weekEndCount += 1;
    33                 }
    34             }
    35             return weekEndCount;
    36         }
  • 相关阅读:
    C#中异步和多线程的区别
    猫 老鼠 人的编程题
    C#中数组、ArrayList和List三者的区别
    经典.net面试题目
    sql有几种删除表数据的方式
    内存池的实现
    A*算法为什么是最优的
    传教士与野人问题
    d3d导致cairo不正常
    c++中的signal机制
  • 原文地址:https://www.cnblogs.com/wangjingblogs/p/3262237.html
Copyright © 2011-2022 走看看