1、
var fmtSettings: TFormatSettings; dt: TDateTime; begin Memo1.Lines.Add(DateTimeToStr(Now)); Memo1.Lines.Add(''); GetLocaleFormatSettings(GetUserDefaultLCID, fmtSettings); Memo1.Lines.Add(fmtSettings.ShortDateFormat); Memo1.Lines.Add(fmtSettings.ShortTimeFormat); Memo1.Lines.Add(fmtSettings.LongDateFormat); Memo1.Lines.Add(fmtSettings.LongTimeFormat); Memo1.Lines.Add(fmtSettings.ThousandSeparator); Memo1.Lines.Add(''); fmtSettings.DateSeparator := '/'; fmtSettings.TimeSeparator := ':'; fmtSettings.ShortDateFormat := 'yyyy/mm/dd'; fmtSettings.ShortTimeFormat := 'hh:nn:ss'; dt:= StrToDateTime('2010/3/19 08:09:10', fmtSettings); Memo1.Lines.Add(DateTimeToStr(dt)); Memo1.Lines.Add(''); fmtSettings.DateSeparator := '/'; fmtSettings.ShortDateFormat := 'yyyy/mm/dd'; fmtSettings.TimeSeparator := ':'; //fmtSettings.ShortTimeFormat := 'hh:nn:ss'; Memo1.Lines.Add(DateTimeToStr(dt, fmtSettings)); Memo1.Lines.Add(DateTimeToStr(now, fmtSettings)); end;
2、输出:
Memo1
2016-10-08 22:42:20
yyyy-MM-dd
h:mm
yyyy'年'M'月'd'日'
h:mm:ss
,
2010-03-19 8:09:10
2010/03/19 8:09:10
2016/10/08 22:42:20
3、
4、
5、