zoukankan      html  css  js  c++  java
  • C#_计算目前时间到指定的周X、指定的时间X 还有多少秒

    比如:当前时间到下周二 05:00:00还剩下多少秒?

     1 /// <summary>
     2 /// 计算距离下一个 周XX XX时XX分XX秒,还剩下多少秒
     3 /// </summary>
     4 /// <param name="currDateTime">当时间</param>
     5 /// <param name="dayWeek">目标星期</param>
     6 /// <param name="str_HourMinuteSecond">目标时间,时分秒的字符串格式 "05:00:00"</param>
     7 /// <param name="totalSeconds">计算结果:还剩下的总秒数</param>
     8 void CalEndTimeSeconds(DateTime currDateTime, DayOfWeek dayWeek, string str_HourMinuteSecond, out int totalSeconds)
     9 {
    10     totalSeconds = 0;
    11     TimeSpan tp = new TimeSpan();
    12     if (TimeSpan.TryParse(str_HourMinuteSecond, out tp))
    13     {
    14         int endPointSeconds = (int)tp.TotalSeconds;
    15 
    16         int currDayPassSeconds = (int)currDateTime.TimeOfDay.TotalSeconds;
    17 
    18         //当天还剩下的秒数
    19         totalSeconds = currDayPassSeconds <= endPointSeconds ? (endPointSeconds - currDayPassSeconds) : (perDaySeconds - currDayPassSeconds);
    20 
    21         if (currDateTime.DayOfWeek > dayWeek)
    22         {
    23             int days = 7 - (int)currDateTime.DayOfWeek;
    24             totalSeconds += days * perDaySeconds;
    25             totalSeconds += endPointSeconds;
    26         }
    27         else if (currDateTime.DayOfWeek == dayWeek)
    28         {
    29             totalSeconds += 0;
    30         }
    31         else
    32         {
    33             int days = (int)(dayWeek - currDateTime.DayOfWeek) - 1;
    34             totalSeconds += days * perDaySeconds;
    35             totalSeconds += endPointSeconds;
    36         }
    37     }
    38 }
  • 相关阅读:
    jsp第二次作业
    jsp第一个作业
    Android应用程序开发
    第十次作业
    int和Integer比较详解
    com.sun.tools.jar下载失败
    JDK1.7和JDK1.8自由切换
    解析excel
    django 2.0配置url捕获参数
    python使用pymysql链接mysql数据库实现增删改查
  • 原文地址:https://www.cnblogs.com/luguoshuai/p/10783883.html
Copyright © 2011-2022 走看看