使用时间跨度比较两个时间间隔 [英] Using Time Span to compare two time intervals

查看:114
本文介绍了使用时间跨度比较两个时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要一定的时间和当前时间来检查它是否超过了规定的时间之间的比较。



我想我应该用时间跨度,但我不知道如何。该两个日期比较即时通讯是datetime对象

 时间跨度TS = TimeSpan.FromSeconds(_timeInterval); 

如果(DateTime.UtcNow.Ticks - rex.LastFired.Ticks> ts.Ticks)
//喇嘛喇嘛


解决方案

 如果(DateTime.UtcNow  -  rex.LastFired> TS)
...


I want to compare between a certain time and the current time to check if it has exceeded a given period.

I think i should be using TimeSpan but i am not sure how. The two dates im comparing are DateTime objects.

 TimeSpan ts = TimeSpan.FromSeconds(_timeInterval);

 if(DateTime.UtcNow.Ticks - rex.LastFired.Ticks > ts.Ticks)
    // bla bla

解决方案

if(DateTime.UtcNow - rex.LastFired > ts)
     ...

这篇关于使用时间跨度比较两个时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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