Delphi日期转字符串的函数

返回字符串格式为
年月日时分秒
其中年4位长度,其他2位长度

这个函数要怎么写

第1个回答  2009-04-29
有现在的函数
var
year, month, day, hour, minute, second, misecond: integer;
begin
DecodeDateTime(now, year, month, day, hour, minute, second, milsecond);
end;

注意在uses里加上DateUtils

不好意思看错题目了~~
那就用FormatDateTime就可以了~~
var
str: string;
begin
str := FormatDateTime('yyyy-mm-dd hh:mm:ss', Now);
end;
第2个回答  推荐于2016-11-01
比如把当前的日期时间转成字符串,放在EDIT1里:
edit1.text:=formatdatetime('yyyy-mm-dd hh:mm:ss',now);
用formatdatetime函数就可以解决。本回答被提问者采纳
第3个回答  2009-04-30
showmessage(datetostr(date));