在C#与德尔福日期/时间计算之间的差距 [英] Disparity between date/time calculations in C# versus Delphi

查看:128
本文介绍了在C#与德尔福日期/时间计算之间的差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

德尔福:

  SecondsBetween(StrToDateTime('16 / 02/2009年下午11时25分34秒),StrToDateTime( 2005年1月1日12:00:00 AM')); 

130289133



C#:

 时间跨度跨度= DateTime.Parse(16/02/2009下午11时25分34秒),减(DateTime.Parse(2005年1月1日12: 00:00 AM)); 

130289134



这不是一致的无论是。一些日期加起来是相同的,即..

 时间跨度跨度= DateTime.Parse(16/11/2011 11: 25:43 PM)减(DateTime.Parse(2005年1月1日12:00:00 AM)); 

SecondsBetween(StrToDateTime('16 /二千零十一分之十一下午11时25分43秒),StrToDateTime(2005年1月1日上午12:00:00'));

都给予

216905143



总数秒,实际使用对数据进行编码,而我试图端口的应用程序为C#,所以甚至连一秒也完全抛出一切都关掉。



谁能解释一下的差距? ,是有办法让C#来匹配德尔福



编辑:在回应建议,这可能是闰秒相关:两个日期范围包含的飞跃等量秒(2),所以你可能认为这两个不匹配。但是相反,我们看到的不一致

  16/02/2009  -  2005年1月1日= Delphi和C#计算不同的总秒

16/11/2011 - 2005年1月1日=他们计算出相同的总秒


< DIV CLASS =h2_lin>解决方案

似乎与此相关的 QC问题59310 的错误是固定在Delphi XE。


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

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.

Can anybody explain the disparity? And is there a way to get c# to match delphi?

Edit: 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

解决方案

The issue it seems related to this QC 59310, the bug was fixed in Delphi XE.

这篇关于在C#与德尔福日期/时间计算之间的差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆