比较DateTime对象

Kev*_*ith 2 c# timestamp

目标 - 找出哪个DateTime更新.

我可以用这段代码搞清楚这一点:

DateTime dt1 = new DateTime(...); //let's say it was created on 1/1/2000

DateTime dt2 = new DateTime(...); //let's say it was create on 1/1/2011 

if (dt2.ToBinary() > dt1.ToBinary()) {
print dt2 is newer than dt1 }
Run Code Online (Sandbox Code Playgroud)

我可以简单地将DateTime对象转换为二进制,然后假设较大的对象是更新的吗?

谢谢,凯文

Sim*_*ier 8

if (dt2 > dt1) {
print dt2 is newer than dt1 }
Run Code Online (Sandbox Code Playgroud)

应该足够,因为DateTime会重载比较运算符.