C#与Delphi之间的日期/时间计算之间的差异 [英] Disparity between date/time calculations in C# versus Delphi
问题描述
Delphi:
SecondsBetween(StrToDateTime('16/02/2009 11:25:34 p.m.'), StrToDateTime('1/01/2005 12:00:00 a.m.'));
130289133
C#:
TimeSpan span = DateTime.Parse("16/02/2009 11:25:34 p.m.").Subtract(DateTime.Parse("1/01/2005 12:00:00 a.m."));
130289134
它也不一致。某些日期会相同,例如..
It's not consistent either. Some dates will add up the same, ie..
TimeSpan span = DateTime.Parse("16/11/2011 11:25:43 p.m.").Subtract(DateTime.Parse("1/01/2005 12:00:00 a.m."));
SecondsBetween(StrToDateTime('16/11/2011 11:25:43 p.m.'), StrToDateTime('1/01/2005 12:00:00 a.m.'));
both give
216905143
实际上用来编码数据的秒数,我试图将应用程序移植到C#,所以即使是一秒钟就完全抛出了一切。
The total amount of seconds is actually being used to encode data, and I'm trying to port the application to C#, so even one second completely throws everything off.
任何人都可以解释差距?有没有办法得到c#来匹配delphi?
Can anybody explain the disparity? And is there a way to get c# to match delphi?
编辑:响应建议,它可能是闰秒相关:两个日期范围包含相同数量的飞跃秒(2),所以你会期望两者不匹配。但是我们看到不一致
In response to suggestions that it might be leap second related: Both date ranges contain the same amount of leap seconds (2), so you would expect a mismatch for both. But instead we're seeing inconsistency
16/02/2009 - 1/01/2005 = Delphi and C# calculate a different total seconds
16/11/2011 - 1/01/2005 = They calculate the same total seconds
推荐答案
这个问题似乎与这个 QC 59310 ,该错误在Delphi XE中得到修复。
The issue it seems related to this QC 59310, the bug was fixed in Delphi XE.
这篇关于C#与Delphi之间的日期/时间计算之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!