Delphi日期转字符串的函数

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:20:09
返回字符串格式为
年月日时分秒
其中年4位长度,其他2位长度

这个函数要怎么写

比如把当前的日期时间转成字符串,放在EDIT1里:
edit1.text:=formatdatetime('yyyy-mm-dd hh:mm:ss',now);
用formatdatetime函数就可以解决。

showmessage(datetostr(date));

有现在的函数
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;