function CheckAvailable () : boolean; begin Result := true; try StrToDateTime (edit1.Text); except on E : Exception do Result := false; end; end;
那你可以用日期/时间控件呀,如TDateTimePciker
function CheckAvailable () : boolean; var sdate,stime: string begin Result := true; sdate:=copy(edit1.text,1,Pos(' ',input.text)-1); stime:=copy(edit1.text,Pos(' ',input.text),length(input.text)-Pos(' ',input.text)+1); try StrToDate(sdate); StrToTime(stime); except on E : Exception do Result := false; end; end;
begin
Result := true;
try
StrToDateTime (edit1.Text);
except on E : Exception do
Result := false;
end;
end;
var sdate,stime: string
begin
Result := true;
sdate:=copy(edit1.text,1,Pos(' ',input.text)-1);
stime:=copy(edit1.text,Pos(' ',input.text),length(input.text)-Pos(' ',input.text)+1);
try
StrToDate(sdate);
StrToTime(stime);
except on E : Exception do
Result := false;
end;
end;
StrToDate(Edit1.Text);
except
ShowMessage('请输入正确的日期类型');
end;想要限制 1982-1-1 12:00:00 那就判断长度。 应该就可以了。