比较时代并获得最大的收益 [英] Comparing Times and get the greatest

查看:72
本文介绍了比较时代并获得最大的收益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我如何比较并获得时间x是否大于时间y?



例子。



 DateTime x = DateTimeNow(); 
DateTime now = DateTime.Now;
TimeSpan diff = now - x;
System.Console.Write( 文件停留时间:time Differnece: + diff) ;

DateTime time = 00:30:00.000;

如果(diff > 时间) // 这是我得到错误的地方
{
System.Console.Write( 文件时间太长:时间不同: + diff);
}
else
{
System.Console.Write( 文件仍然是新的: + diff);
}





提前感谢您的帮助。

解决方案

< blockquote> DateTime 时间点,其中 TimeSpan 持续时间

考虑到这一点,想一想!



两个时间点之间的差异是持续时间。

例如昨天中午(一个时间点)和今天中午(一个时间点)之间的差异是24小时(持续时间)。



两个持续时间之间的差异是再次持续时间。

例如5分钟(持续时间)和3分钟(持续时间)之间的差异是2分钟(持续时间)。



现在你可以详细说明添加/减去持续时间的含义/持续时间/持续时间/时间点。

但是有些组合可能没有意义。



最后, DateTime TimeSpan 可能无法提供上述所有可能的操作。



干杯

Andi


 DateTime first = GetFirstDate(); 
DateTime second = GetSecondDate();

if (first.Date.Equals(second.Date))
{
// 日期相等
}

in linq:

e = > DateTime.Compare(e.FirstDate.Value,SecondDate)> = 0


您正在比较DateTime到了TimeSpan。我想你的意思是

 TimeSpan time = new TimeSpan(0,30,0); 
if(diff> time)...


Hi How do I compare and get if time x is greater than time y?

EXAMPLE.

DateTime x = DateTimeNow();
DateTime now = DateTime.Now;
TimeSpan diff = now - x;
System.Console.Write("File over stayed : time Differnece : " + diff); 

DateTime time = "00:30:00.000";
  
if (diff > time ) //This is where I get an Error
{
   System.Console.Write("File time too long : time Differnece : " + diff);
}
else
{
   System.Console.Write("File still new :"+diff);
}



Thanks in advance for your help.

解决方案

DateTime is a point in time, where as TimeSpan is a duration.
With this in mind, think of it!

The difference between two points in time is a duration.
E.g. the difference between yesterday noon (a point in time) and today noon (a point in time) is 24 hours (a duration).

The difference between two durations is a duration again.
E.g. the difference between 5 minutes (duration) and 3 minutes (duration) is 2 minutes (duration).

Now you can elaborate yourself what it means to add/subtract durations/points in time to/from durations/points in time.
Some combinations may not be meaningful, though.

Finally, the DateTime and TimeSpan may not provide all possible operations from above.

Cheers
Andi


DateTime first = GetFirstDate();
DateTime second = GetSecondDate();

if (first.Date.Equals(second.Date))
{
    // the dates are equal
}

in linq:

e => DateTime.Compare(e.FirstDate.Value, SecondDate) >= 0


You are comparing a DateTime to a TimeSpan. I think you meant

TimeSpan time = new TimeSpan(0, 30, 0);
if(diff > time) ...


这篇关于比较时代并获得最大的收益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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