欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  470 随笔 :: 0 文章 :: 22 评论 :: 30万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
private void button5_Click(object sender, EventArgs e)
       {
           string str = "8.00~12.30";
           int index = str.IndexOf('~');
           int length = str.Length - index - 1;
           string begin = str.Substring(0, index);
           string end = str.Substring(index + 1, length);
 
           string timea = "8:30";
           string timeb = "11:30";
           DateTime beginTime = Convert.ToDateTime(timea);
           DateTime endTime = Convert.ToDateTime(timeb);
 
           var aaa = GetTimeLength(beginTime, endTime);
           var bbb = GetTimeLenght2(beginTime, endTime);
           MessageBox.Show("GetTimeLength==" + aaa + "\r\n" + bbb);
       }
 
       public string GetTimeLength(DateTime beginTime, DateTime endTime)
       {
           try
           {
               string timeLength = string.Empty;
               TimeSpan begin = new TimeSpan(beginTime.Ticks);
               TimeSpan end = new TimeSpan(endTime.Ticks);
               TimeSpan ts = begin.Subtract(end).Duration();
 
               timeLength = Convert.ToString(ts.Hours * 60 + ts.Minutes);
 
               return timeLength;
           }
           catch
           {
           }
           return string.Empty;
       }
 
 
       public string GetTimeLenght2(DateTime DateTime1, DateTime DateTime2)
       {
           string dateDiff = string.Empty;
           try
           {
               TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
               TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
               TimeSpan ts = ts1.Subtract(ts2).Duration();
               string hours = ts.Hours.ToString(), minutes = ts.Minutes.ToString(), seconds = ts.Seconds.ToString();
               if (ts.Hours < 10)
               {
                   hours = "0" + ts.Hours.ToString();
               }
               if (ts.Minutes < 10)
               {
                   minutes = "0" + ts.Minutes.ToString();
               }
               if (ts.Seconds < 10)
               {
                   seconds = "0" + ts.Seconds.ToString();
               }
               dateDiff = hours + ":" + minutes + ":" + seconds;
           }
           catch
           {
           }
           return dateDiff;
       }

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
string str = this.txtvalue.Text;// "13.30~14.30";
            int index = str.IndexOf('~');
            int length = str.Length - index - 1;
            string startT = str.Substring(0, index);
            string endT = str.Substring(index + 1, length);
 
            DateTime currentTime = DateTime.Parse(DateTime.Now.ToString("HH:mm"));
            DateTime beginTime = Convert.ToDateTime(startT.Replace('.', ':'));
            DateTime endTime = Convert.ToDateTime(endT.Replace('.', ':'));
            string minutes = GetTimeLength(beginTime, currentTime);
 
            string end1 = str.Substring(index + 1, length);
            TimeSpan endTime1 = DateTime.Parse(end1.Replace('.', ':') + ":59").TimeOfDay;
            TimeSpan currentDT = DateTime.Now.TimeOfDay;
            //过时签到
            if (currentDT > endTime1)//已过签到时间
            {
                MessageBox.Show("已过时无法签到==" + minutes);
            }
            //时间段内签到  || int.Parse(minutes) <= int.Parse(this.txtNo.Text)
            else  if (currentTime > beginTime && currentTime <= endTime)
            {
                MessageBox.Show("签到成功2==" + minutes);
            }
            //提前签到 --当前时间小于签到开始时间
            else if (int.Parse(minutes) <= int.Parse(this.txtNo.Text) && currentTime < beginTime)
            {
                MessageBox.Show("签到成功1==" + minutes);
            }
            else if (int.Parse(minutes) >= int.Parse(this.txtNo.Text) && currentTime < beginTime)
            {
                MessageBox.Show("签到时间未到,无法签到==" + minutes);
            }

  

posted on   sunwugang  阅读(233)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2019-04-28 Winfrom BackgroundWorker
2019-04-28 Winform 界面执行耗时操作--UI卡顿假死问题
点击右上角即可分享
微信分享提示