简体   繁体   English

将C ++ time_t转换为Delphi TDateTime

[英]Convert a C++ time_t to Delphi TDateTime

In a Delphi XE application, I am reading values from a database originally created by a C++ program. 在Delphi XE应用程序中,我正在从最初由C ++程序创建的数据库中读取值。 There is a date column, stored (it would appear) as time_t, ie Unix time, the number of seconds since 00:00, Jan 1, 1970 UTC. 有一个日期列,存储(它会显示)为time_t,即Unix时间,自UTC时间00:00,1970年1月1日以来的秒数。 I can deal with the time zone, but how can I get TDateTime from (long) time_t? 我可以处理时区,但是如何从(长)time_t获得TDateTime?

尝试使用作为Dateutils单元一部分的unixtodatetime函数: http ://docwiki.embarcadero.com/VCL/en/DateUtils.UnixToDateTime

If you want to do it yourself for some reason, the obvious approach would be to divide the time_t by the number of seconds in a day, then add that to a TDateTime for 00:00, Jan 1, 1970. 如果你想出于某种原因自己做,显而易见的方法是将time_t除以一天中的秒数,然后将其添加到1970年1月1日00:00的TDateTime。

(But RRUZ answer should work and means you don't have to reinvent the wheel). (但RRUZ的答案应该起作用,意味着你不必重新发明轮子)。

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

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