开发者

c# compare datetime for day of month and time

开发者 https://www.devze.com 2023-03-13 12:16 出处:网络
I need to compare two datetime variable only for some cri开发者_如何学运维teria : Day of the month and time .

I need to compare two datetime variable only for some cri开发者_如何学运维teria : Day of the month and time .

If the day of the month and the time is equal to another datetime then the expression return true, the comparison must not keep in mind of the month and the year of the two Datetime .

What's the best way to do this comparison ?

Thanks.


Compare the Day and the TimeOfDay properties of the two DateTime values:

bool areEqual = (d1.Day == d2.Day)
             && (Math.Abs((d1.TimeOfDay - d2.TimeOfDay).TotalSeconds) < 1.0);

Adjust for different time zones before comparing if necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消