Ignore milliseconds when comparing two datetimes

前端 未结 14 2286
一个人的身影
一个人的身影 2020-12-08 12:47

This is probably a dumb question, but I cannot seem to figure it out. I am comparing the LastWriteTime of two files, however it is always failing because the file I download

14条回答
  •  死守一世寂寞
    2020-12-08 13:24

    Care should be taken, if dt has non-zero microseconds (fractions of millis). Setting only milliseconds to zero is not enough.
    To set millis and below to zero (and get a succesfull comparison), the code would be:

    dt = dt.AddTicks(-dt.Ticks % TimeSpan.TicksPerSecond); // TimeSpan.TicksPerSecond=10000000
    

提交回复
热议问题