procedure TForm3.Button1Click(Sender: TObject); var MySettings: TFormatSettings; s: string; d: TDateTime; begin GetLocaleFormatSettings(GetUserDefaultLCID, MySettings); MySettings.DateSeparator := '-'; MySettings.TimeSeparator := ':'; MySettings.ShortDateFormat := 'mm-dd-yyyy'; MySettings.ShortTimeFormat := 'hh:nn:ss'; s := DateTimeToStr(Now, MySettings); ShowMessage(s); d := StrToDateTime(s, MySettings); ShowMessage(DateTimeToStr(d, MySettings)); end;
However, if you used 'mmm-dd-yyyy' as the ShortDateFormat in the example above (to display Jan-09-2006), you would get an error when calling StrToDateTime on this string. The workaround is to call d := VarToDateTime(s) instead, since that function supports month names when encoding the TDateTime. I logged this bug as QC 23301, so if you'd like to see this fixed, please rate this entry and vote on it if it's important enough to you.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.