“xx-xx-xx不是有效的日期和时间值”错误

时间:2011-02-16 12:22:23

标签: delphi datetime

从我的last question跟进,每当我在具有不同日期/时间格式的系统上运行它时,我仍会收到错误。我正在使用日期编辑和时间编辑框来选择我的日期和时间值。日期编辑格式为dd-mm-yy,我的时间编辑格式为hh:mm。当我将它们保存到TDateTime变量dtLastOnline时,我得到'xx-xx-xx不是有效的日期和时间值'错误。

我将dtLastOnline设置为dtLastOnline := dedtLastOnline.Date + tpLastOnline.Time;

如何确保我的应用程序在运行的任何地方都具有相同的日期/时间格式?

我尝试设置ShortDateFormat,LongDateFormat等,但这不起作用。

谢谢!

1 个答案:

答案 0 :(得分:3)

我尝试了两个TDateTimePickers,一个用于保存数据,一个用于保留时间。那是你在做什么?

我发现以下内容适用于我而没有错误:

var
  dt: TDateTime;
  ...
dt := DateOf(DatePicker.Date) + TimeOf(TimePicker.Time);
ShowMessage(FormatDateTime('c', dt));

输出结果为:

enter image description here