Text:=IntToStr(wYear)+’年’+IntToStr(wMonth)+’月’ +IntToStr(wDay)+’日’;
else {默认为:”yyyy年mm月dd日”的格式.}
Text:=IntToStr(wYear)+’年’+IntToStr(wMonth)+’月’ +IntToStr(wDay)+’日’;
end;
end;
function DateFieldSetText(Sender: TField; const Text: String):Boolean;
var
dDate:TDate;
sYear,sMonth,sDay:String;
aryTestYMD:Array [1..2] of Char;
iYMD:Integer;
begin
{获得用户输入的日期}
sYear:=Copy(Text,1,4);
sMonth:=Copy(Text,7,2);
SDay:=Copy(Text,11,2);
{测试输入掩码所包含的格式.}
aryTestYMD:=’年’;
if StrScan(PChar(Sender.EditMask),
aryTestYMD)< >nil then
iYMD:=1;
aryTestYMD:=’月’;
if StrScan(PChar(Sender.EditMask),
aryTestYMD)< >nil then
iYMD:=2;
aryTestYMD:=’日’;
if StrScan(PChar(Sender.EditMask),
aryTestYMD)< >nil then
iYMD:=3;
{利用Try…Except进行输入的日期转换}
try
begin
case iYMD of
1: {输入掩码为:”yyyy年”的格式.}
begin
dDate:=StrToDate(sYear+’-01-01’) ;{中文Windows默认的日期格式为:yyyy-mm-dd.下同}
Sender.AsDateTime:=dDate;
end;
2: {输入掩码为:”yyyy年mm月”的格式.}
begin
dDate:=StrToDate(sYear+’-’+sMonth+’-01’);
Sender.AsDateTime:=dDate;
end;
3: {输入掩码为:”yyyy年mm月dd日”的格式.}
begin
dDate:=StrToDate(sYear+’-’+sMonth+’-’+sDay);
Sender.AsDateTime:=dDate;
end;
else {默认为:”yyyy年mm月dd日”的格式.}
begin
dDate:=StrToDate(sYear+’-’+sMonth+’-’+sDay);
Sender.AsDateTime:=dDate;