简体   繁体   English

DBGrid中的“我的时间”字段显示的是日期和时间,而不是仅显示时间-Delphi

[英]My Time Field in my DBGrid is showing the date and time instead of time only - delphi

I have a field in my database called 'Times', it's a date/time format and its format is set to 'short time'. 我的数据库中有一个名为“时间”的字段,它是日期/时间格式,其格式设置为“短时间”。 In my database the date does not show, nor is it being add to the database as I know. 在我的数据库中,日期不显示,也不据我所知被添加到数据库中。 It is only the time value. 它只是时间值。 My DBGrid shows the time field with the time value and the date '12/30/1899'. 我的DBGrid显示带有时间值和日期'12 / 30/1899'的时间字段。 How do I get rid of the date in my time field. 如何摆脱时间字段中的日期。

Here is the code I used to submit to the database. 这是我用来提交到数据库的代码。 Get time value: 获取时间值:

bookingtimes:= timeof(dttime.Time);

Submit to Database: 提交到数据库:

 tblbooking.FieldByName('Times').AsDateTime:=bookingtimes;

Example of DBGrid 'Times' column output: DBGrid“时间”列输出示例:

12/30/1899 7:02:01AM

If I understand what you mean this will work for you, just follow this steps: 如果我了解您的意思,这对您有用,请按照以下步骤操作:

  • This is your issue: 这是您的问题:

  • Double click on your table, and select Times field: 双击表,然后选择Times字段:

  • After you click on your field, go to the Object Inspector and find DisplayFormat property: 单击字段后,转到“ Object Inspector并找到DisplayFormat属性:

  • Write the format , in your case hh:mm:ss : 在您的情况下,写format hh:mm:ss

  • Now let's see the result: 现在让我们看一下结果:

That's it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM