[英]The best way to compare DateTime?
The problem is the best way to compare DateTime form the past with now. 问题是比较过去和现在的DateTime的最佳方法。 I try to diff a past of time with DateTime now but It's not absolutely solve my problem.
我现在尝试使用DateTime来比较过去的时间,但这不能完全解决我的问题。 The function I have try is here =>
我尝试的功能在这里=>
public void diffOfEpochTime(DateTime past_time){
double howlong = (DateTime.Now() - past_time).TotalDays;
Console.write(howlong/365.25 + " Year "
+ (howlong%365.25)/30 + " Month "
+ (howlong%365.25)%30 + " Day");
}
Seem like it's work but actually not because the diff of time is missed some of month and day. 看起来像是在工作,但实际上不是因为在某个月和一天中错过了时间差异。
Example the Time is January 1, 2018 12:00:00 AM and today is March 1, 2018 12:00:00 AM the answer should be 0 Year 2 Month 1 Day. 例如,时间为2018年1月1日12:00:00 AM,今天为2018年3月1日12:00:00 AM,答案应为0年2个月1天。 but the Function's answer is 0 Year 1 month 29 Day
但函数的答案是0年1个月29天
Anyone have a suggestion to me how to dare with this, Thank you. 有人对我有一个建议,我怎么敢做,谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.