打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How lowest or highest accepted date and time (TDateTime usage) on Delphi?
作者:
emailx45 (emailx45)▲▲▲▲△-
注册会员
2022/3/27 5:31:41
标题:How lowest or highest accepted date and time (TDateTime usage) on Delphi? by Emailx45浏览:42
加入我的收藏
楼主:For technical reasons, and luckily, Delphi (Object Pascal) forces us to work with typed values.
That is, each object or value must be properly documented in the language before it can be used.
In this way, the most innocent mistake of the programmer can be accused even before compiling the source code.
Again, this has no guarantee about your own innate intellectual ignorance!
However, this type of approach makes a big difference between untyped languages, very common in the recent past.
Another point that I must emphasize, and that, because it is a language that allows a wide performance of the fertile imagination that the human being has, it allows the programmer to create the most aberrant definitions that he deems to be correct!
So, after all the above philosophy, let's get back to the point!
TDateTime = type Double;
The Double type (currently in RAD Studio 11.1 edition, in Delphi), allows the range of values between: {all current platforms}
type:
- Double : 2.23e-308 .. 1.79e+308   ( 308 zeros)
--  Significant decimal digits: 15-16
--  Size in bytes: 8
On Delphi:
- Lowest TDateTime: December 30, 1899; 12:00 A.M.
- Highest TDateTime: December 31, 9999 23:59:59.999;
TDateTime accept values:
-Lowest: -693593.00000001;// 01/01/0001 00:00:00.001 = lowest accepted valid DateTime
------>  -1.900,xxxx years
-Highest: 669528949.999999940;// 12/31/65535 23:59:59,990 = highest accepted to valid DateTime
------>  23.920.275 days
On Delphi 11.1 Alexandria
TDatePicker (Win 10):
- Lowest Date : 01/01/0001
- Highest Date: 12/31/9999
TDateTimePicker (Win32)
- Lowest Date : 01/01/1601
- Highest Date: 12/31/9999
..........
begin
try
// many DateTime function works like this: xxxDEF(  datetime-value, datetime-value-if-any-error );
//
// StrToDateTime()...  StrToDateTimeDef(  datetime-value, datetime-value-if-any-error );
//
// MyDateTime := -693593.00000001;
// MyDateTime := 669528949.999999940;
//
MyDate := StrToDateTime('25/03/2022 17:40:20');
MyTime := StrToTime('17:40:20');
//
Edit1.Text := DateTimeToStr(MyDate * 4);  // 08/12/2388 22:41:20
Edit1.Text := DateTimeToStr(MyDate - 30); // 23/02/2022 17:40:20
Edit1.Text := DateTimeToStr(MyDate / 5);  // 11/06/1924 03:32:04
//
Edit1.Text := DateTimeToStr(MyTime * 1.2); // 30/12/1899 21:12:24
Edit1.Text := DateTimeToStr(MyTime - 0.5); // 30/12/1899 05:40:20
Edit1.Text := DateTimeToStr(MyTime / 2.2); // 30/12/1899 08:01:58
except
on E: Exception do
ShowMessage('My error: ' + E.Message);
end;
end;此帖子包含附件:
大小:9.2K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!
作者:
emailx45 (emailx45)▲▲▲▲△-
注册会员
2022/3/27 5:43:24
1楼:NOTE:
any other value than this can:
--- be a Date/Time invalid.
--- start a new Date/Time from start ( ...-3,-2,-1...0...1,2,3,...)
Delphi try return a valid Date/Time until that is not more possible, and raise an "is not a valid date/time".
MyDateTime := -693593.00000001;
MyDateTime := 669528949.999999940;
Edit1.Text := (TDateTime(669528949.999999940) + TDateTime( {+} 693593.00000001)).ToString; // 670.222.542 days = 1.836.226 years  >:()
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!
作者:
emailx45 (emailx45)▲▲▲▲△-
注册会员
2022/3/27 6:22:36
2楼:  MyDateInDoubleValue := -693593.00000001; // 01/01/0001 00:00:00.001 = lowest accepted valid DateTime!
//
MyDateInDoubleValue := cardinal.MaxValue; // 0..4294967295 = 29/12/1899 00:00:00.000 // max value accepted!
MyDateInDoubleValue := cardinal.MinValue; // 0..4294967295 = 30/12/1899 00:00:00.000
//
MyDateInDoubleValue := integer.MaxValue; // -2147483648..2147483647 = 00/00/0000 00:00:00.000
MyDateInDoubleValue := integer.MinValue; // -2147483648..2147483647 = 00/00/0000 00:00:00.000
//
MyDateInDoubleValue := smallint.MaxValue; // -32768..32767 = 16/09/1989 00:00:00.000
MyDateInDoubleValue := smallint.MinValue; // -32768..32767 = 13/04/1810 00:00:00.000
//
// DEcodeDate(), ENcodeDate() usage "WORD" type;
MyDateInDoubleValue := word.MaxValue; // 0..65535 = 04/06/2079 00:00:00.000
MyDateInDoubleValue := word.MinValue; // 0..65535 = 30/12/1899 00:00:00.000
//
MyDateInDoubleValue := byte.MaxValue; // 0..255 = 11/09/1900 00:00:00.000
MyDateInDoubleValue := byte.MinValue; // 0..255 = 30/12/1899 00:00:00.000
//
MyDateInDoubleValue := 669528949.999999940; // 31/12/65535 23:59:59.990 highest accepted to valid DateTime! = 23.920.275 days
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi中关于时间差的实例
delphi 时间差函数及部分字符串与日期时间相互转换的函数
Delphi中TDateTime使用心得
各种时间类型之间的转换函数
delphi用于时间操作的函数 (2) - - JavaEye技术网站
Dynamic Method Invocation in Delphi
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服