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         }
  • 相关阅读:
    OpenCR 固件修复
    E-PUCK2机器人-固件更新
    E-puck2机器人系列教程-2.软件的安装与使用
    E-PUCK2机器人-硬件
    E-puck2机器人系列教程-固件修复升级
    GridView
    TimePicker 和TimePickerDiag
    android中实现简单的播放
    ListView的使用
    android的activity的跳转
  • 原文地址:https://www.cnblogs.com/wangjingblogs/p/3262237.html
Copyright © 2011-2022 走看看