如何比较DateTime对象? [英] How to compare DateTime Objects?

查看:75
本文介绍了如何比较DateTime对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..


谁能告诉我如何比较日期时间对象?我有三个

对象即当前日期,开始日期和结束日期..我需要检查

当前日期与开始日期和结束日期.... Plz告诉我如何

比较???


Thanx ..

Krish

解决方案

嗨Krish,


查看DateTime.Compare方法!


// Jesper


< ;共******* @ gmail.com>写道:

谁能告诉我如何比较日期时间对象?我有三个
对象即当前日期,开始日期和结束日期..我需要检查
当前日期与开始日期和结束日期.... Plz告诉我如何比较???




假设你要检查它是否'在开始结束的范围内,

只需使用:


if(start< = current&&

当前< =结束)

{

//它在范围内

}


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件


< JE ************ @ yahoo.se>写道:

查看DateTime.Compare方法!




虽然您当然可以使用DateTime.Compare,但代码将更多

如果您只使用<,< =,>和> =运营商。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复对于小组,请不要给我发邮件


Hi all..

Can anyone tell me how to compare datetime objects?I ve three
objects namely Current date,start date and end date.. I need to check
the current date with Start date and end date....Plz tell me how to
compare ???

Thanx..
Krish

解决方案

Hi Krish,

Check out DateTime.Compare method !

// Jesper


<co*******@gmail.com> wrote:

Can anyone tell me how to compare datetime objects?I ve three
objects namely Current date,start date and end date.. I need to check
the current date with Start date and end date....Plz tell me how to
compare ???



Assuming you''re trying to check whether it''s in the range start-end,
just use:

if (start <= current &&
current <= end)
{
// It''s in the range
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


<je************@yahoo.se> wrote:

Check out DateTime.Compare method !



While you certainly can use DateTime.Compare, the code will be more
readable if you just use the <, <=, > and >= operators.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于如何比较DateTime对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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