function DateTostring(val:string):string;定义一个函数; procedure TForm1.Button1Click(Sender: TObject); begin DateTimePicker1.DateTime:=StrToDate(datetostring(edit1.Text)); end;function TForm1.DateTostring(val: string):string; var I:Integer;begin for I:= 1 to Length(val)do begin if (i=4) or (i=6) then Result:=Result+val[i]+'-' else Result:=Result+val[i]; end; end;具体情况参考一下上面的.我刚刚做的.
procedure TForm1.Button1Click(Sender: TObject); var str:string; Year,Mon,Date:Word; begin str:='20050419'; Date:=StrToInt(str) mod 100; Mon:=(StrToInt(str) div 100) mod 10; Year:=StrToInt(str) div 10000; Label1.Caption:=FormatDatetime('yyyy-mm-dd',EnCodeDate(Year,Mon,Date)); end;
Mon:=(StrToInt(str) div 100) mod 10; --------------->>>>>>>>>>>... Mon:=(StrToInt(str) div 100) mod 100;
procedure TForm1.Button1Click(Sender: TObject); begin try DateTimePicker1.DateTime:=StrToDate(datetostring(edit1.Text)); except DateTimePicker1.DateTime:=StrToDate(datetostring2(edit1.Text));//解决转换六个字像021212 end; end;function TForm1.DateTostring(val: string):string; var I:Integer; begin for I:= 1 to Length(val)do begin if (i=4) or (i=6) then Result:=Result+val[i]+'-' else Result:=Result+val[i]; end; end; function TForm1.DateTostring2(val: string):string; var I:Integer; begin for I:= 1 to Length(val)do begin if (i=2) or (i=4) then Result:=Result+val[i]+'-' else Result:=Result+val[i]; end; end;
Str:= FormatDateTime('yyyy-mm-dd', StrToDate('20050419'));
procedure TForm1.Button1Click(Sender: TObject);
begin
DateTimePicker1.DateTime:=StrToDate(datetostring(edit1.Text));
end;function TForm1.DateTostring(val: string):string;
var
I:Integer;begin
for I:= 1 to Length(val)do begin
if (i=4) or (i=6) then
Result:=Result+val[i]+'-'
else Result:=Result+val[i];
end;
end;具体情况参考一下上面的.我刚刚做的.
var
str:string;
Year,Mon,Date:Word;
begin
str:='20050419';
Date:=StrToInt(str) mod 100;
Mon:=(StrToInt(str) div 100) mod 10;
Year:=StrToInt(str) div 10000; Label1.Caption:=FormatDatetime('yyyy-mm-dd',EnCodeDate(Year,Mon,Date));
end;
--------------->>>>>>>>>>>...
Mon:=(StrToInt(str) div 100) mod 100;
begin
try
DateTimePicker1.DateTime:=StrToDate(datetostring(edit1.Text));
except
DateTimePicker1.DateTime:=StrToDate(datetostring2(edit1.Text));//解决转换六个字像021212
end;
end;function TForm1.DateTostring(val: string):string;
var
I:Integer;
begin
for I:= 1 to Length(val)do begin
if (i=4) or (i=6) then
Result:=Result+val[i]+'-'
else Result:=Result+val[i];
end;
end;
function TForm1.DateTostring2(val: string):string;
var
I:Integer;
begin
for I:= 1 to Length(val)do begin
if (i=2) or (i=4) then
Result:=Result+val[i]+'-'
else Result:=Result+val[i];
end;
end;