【问题标题】:How to use FormatDateTime to return a default date concatenated with current year?如何使用 FormatDateTime 返回与当前年份连接的默认日期?
【发布时间】:2011-11-07 16:12:04
【问题描述】:

我使用的是 Delphi 2007。

我需要编写一个 FormatDateTime 函数,该函数始终将 01/01/ 作为 EditValue 返回到 TDateEdit 框(DevExpress 组件)。

我已经试过了……

tcxDateEdit1.EditValue := FormatDateTime('01/01/'+ 'yyyy',now);

和

tcxDateEdit1.EditValue := FormatDateTime('01/01/yyyy',Now);

但他们都没有工作。 它导致将字符串类型的变体转换为双精度的错误。 “无法将类型(String)的变体转换为类型(Double)”

【问题讨论】:

    标签: delphi date delphi-2007 formatdatetime


    【解决方案1】:

    我只是在猜测,但您的 EditValue 属性似乎属于 TDateTime(或 TDate)类型(而 FormatDateTime 返回 string)。如果是这样,您可以尝试以下方法:

    tcxDateEdit1.EditValue := EncodeDate(YearOf(Now), 1, 1);
    

    另请参阅:YearOf、EncodeDate、FormatDateTime 文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-01
      相关资源
      最近更新 更多