【发布时间】:2013-10-03 17:02:09
【问题描述】:
我需要知道类型变量 TDateTime、TDate 和 TTime。
有人知道怎么做吗?
我用下面的代码,结果是“Is NOT TDateTime”,“Is NOT TDate”,“Is NOT Ttime”
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.Rtti,
System.SysUtils;
var
DateTime, Date,Time: TValue;
begin
DateTime:= StrToDateTime( '01/01/2013 01:05:09' );
if ( DateTime.TypeInfo = System.TypeInfo(TDateTime) ) then
Writeln( 'Is TDateTime' )
else
Writeln( 'Is NOT TDateTime' );
Date:= StrToDate( '01/01/2015' );
if ( Date.TypeInfo = System.TypeInfo(TDate) ) then
Writeln( 'Is TDate' )
else
Writeln( 'Is NOT TDate' );
Time:= StrToTime( '01:01:02' );
if ( Date.TypeInfo = System.TypeInfo(TTime) ) then
Writeln( 'Is TTime' )
else
Writeln( 'Is NOT TTime' );
Readln;
end.
谢谢
【问题讨论】:
-
也许你可以尝试关注答案
from here。 -
欢迎来到 Stack Overflow。将您预期获得的结果包含在内非常好,但报告您获得的结果而不是也很有帮助。您知道您没有获得 TDateTime,因此请进一步调查并找出您获得的类型。另请注意,StrToDateTime、StrToDate 和 StrToTime 都返回 TDateTime,因此不要对区分它们抱有太大希望。
-
类型始终为
TDateTime。 -
不,类型总是
Extended- 请参阅下面的答案。