var
Date: TDateTime;
FormatSettings: TFormatSettings;
begin
Date := Now;//获取当天时间
ShowMessage(DateToStr(Date)); //当天时间 2017-05-15 (输入的日期格式以系统的时间格式为准,我系统的时间格式是yyyy-MM-dd,这点需要留意,
//最好使用TFormatSettings对时间进行格式化)
Date := Date-2;//减去2天
{自定义时间输出格式}
FormatSettings.ShortDateFormat:='yyyy/MM/dd';
FormatSettings.DateSeparator:='/';
FormatSettings.TimeSeparator:=':';
FormatSettings.LongTimeFormat:='hh:mm:ss.zzz';
{end}
ShowMessage(DateToStr(Date,FormatSettings));// 2017/05/13
end;