gpt4 book ai didi

delphi - 是否有 Delphi EncodeDate/DecodeDate 函数版本可以处理 B.C.日期?

转载 作者:行者123 更新时间:2023-12-03 14:39:03 31 4
gpt4 key购买 nike

Delphi 函数 EncodeDate/DecodeDate 似乎只能处理 1.1.0001 之后的日期。是否有一些 EncodeDate/DecodeDate 的实现可以处理 B.C. tDateTime 值?

最佳答案

AFAIK TDateTime 是一种 Windows 基本类型,常见于 COM、Variants、DotNet 和 Delphi。负值可用于 1899 年之前的日期。

但这并不是那么简单 - 因为负值会带来一些麻烦,如 stated by this page :

The integral part is the date, the fraction is the time. Date.time. That's easy. Things get odd when the value is negative. This is on or before #12/30/1899#.

With modern dates time always runs forwards, as you would suspect. With negative historical dates time actually runs backwards! Midnight #1/1/1800# equals −36522, but noon #1/1/1800# is −36522.5 (less than midnight!) and one second before midnight is −36522.9999884259 (even less). At midnight the clock jumps forward to -36521, which equals #1/2/1800#. The decimal fraction still shows the time and the integral part is the date, but each second decrements the clock while each new day increments it, not just by 1, but by almost 2. Negative times are really counterintuitive.

To make things worse, time values for #12/30/1899# are ambigous in two ways. First, a time value without a date equals that time on #12/30/1899#. This means that 0.5 is either noon or noon on #12/30/1899#, depending on context. Zero is either midnight, #12/30/1899# or midnight #12/30/1899#. The other ambiguity is that all time values come in double for #12/30/1899#. 0.5 is noon #12/30/1899#, but -0.5 is noon #12/30/1899# as well. The integral part is the date, the fraction is the time. Another surprise is here: #12/30/1899 11:59:59 PM# - #12/29/1899 11:59:59 PM# = 2.99997685185185. Not 1, what you normally would expect for a 24-hour period. Be careful when working with historical dates.

据我所知,EncodeDate/DecodeDate 的当前实现可以工作,但是在使用负值或接近于零的 TDateTime 值时可能会遇到麻烦...

您最好使用自己的时间格式,例如ISO-8601 或这样的简单记录:

TMyDateTime = packed record
Year: SmallInt;
Month: Byte;
Day: Byte;
end;

当计算有关持续时间或显示日期/时间的内容时,您必须意识到“我们的时间”不是连续的。因此,使用 TDateTime=double 技巧进行的计算并不总是按预期工作。例如,我记得Teresa of Avila died in 1582, on October 4th ,正如天主教国家从儒略历转换为公历一样,这需要从日历中删除 10 月 5 日至 14 日。 :)

关于delphi - 是否有 Delphi EncodeDate/DecodeDate 函数版本可以处理 B.C.日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6856757/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com