检查差以秒两个时间之间 [英] Check difference in seconds between two times

查看:102
本文介绍了检查差以秒两个时间之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我目前正在当某一事件发生有关,包括发生被添加到一个列表阵列事件时事件的详细信息,其中一个项目。

Hi all I am currently working on a project where when a certain event happens details about the event including the time that the event occurred is added into a list array.

一旦方法完成,然后我通过列表来检查它的价值的另一种方法上。我通过循环之前我检查我的电脑的当前时间,我需要检查保存列表阵列和当前时间之间的时间差是否大于5秒。

Once the method has finished I then pass on the list to another method that checks its values. Before I go through the loop I check the current time of my PC and I need to check whether the difference between the time saved in the list array and the current time is greater than 5 seconds.

我怎么会去这样做。

推荐答案

假设 dateTime1 DATETIME2 的DateTime 值:

Assuming dateTime1 and dateTime2 are DateTime values:

var diffInSeconds = (dateTime1 - dateTime2).TotalSeconds;

在你的情况,你倒是用 DateTime.Now 作为值之一,并在列表作为其他的时间。要注意顺序,因为其结果可能是负面的,如果 dateTime1 DATETIME2 更早。

In your case, you 'd use DateTime.Now as one of the values and the time in the list as the other. Be careful of the order, as the result can be negative if dateTime1 is earlier than dateTime2.

这篇关于检查差以秒两个时间之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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