delphi中 怎么把字符串yyyy年mm月dd日转换成日期格式

如题所述

第1个回答  2011-02-22
使用字符串转日期函数:strtodatetime
第2个回答  2011-02-22
myDateTime : TDateTime;
myDateTime := StrToDateTime('22/02/2011 12:34:56');
第3个回答  2011-02-23
StrToDate
第4个回答  2011-02-22
var
i: integer;
str: string;
sYear, sMonth, sDay: string;
dt: TDateTime;
begin
str := 'yyyy年mm月dd日';
i := pos('年', str);
sYear := copy(str, 1, i-1);
System.delete(str, 1, i);
i := pos('月', str);
sMonth := copy(str, 1, i-1);
System.Delete(str, 1, i);
i := pos('日', str);
sDay := copy(str, 1, i-1);
dt := StrToDateTime(sYear + '-' + sMonth + '-' + sDay);
end;本回答被提问者采纳