当我为getdate()添加时间时,我希望在结束时关闭一天 [英] When I added time to getdate() , I want to stop when day closed at a end time

查看:62
本文介绍了当我为getdate()添加时间时,我希望在结束时关闭一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

when i added time to getdate() , i want to stop when day closed at a end time





喜欢今天26/2/2018 20:00:00 pm我想停止27/2/2018 00:00:00 in while循环



我尝试过:



喜欢今天26/2/2018 20:00:00 pm我想停止27/2/2018 00: 00:00 in while循环



like today 26/2/2018 20:00:00 pm i want to stop 27/2/2018 00:00:00 in while loop

What I have tried:

like today 26/2/2018 20:00:00 pm i want to stop 27/2/2018 00:00:00 in while loop

推荐答案

添加任意时间跨度并不总能达到目标。你能做的最好的事情是检测它何时更大。类似于:

Adding an arbitrary time span wouldn't always hit the target. The best you can do is detect when it is greater. Something like:
System.DateTime dt = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan(0, 1, 5, 0);

int day = dt.Day;
while (dt.Day == day)
{
  Console.WriteLine(dt.ToString());
  dt = dt.Add(duration);
}


这篇关于当我为getdate()添加时间时,我希望在结束时关闭一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆