开发者

Convert a C++ time_t to Delphi TDateTime

开发者 https://www.devze.com 2023-02-10 22:57 出处:网络
In a Delphi XE application, I am reading values from a database originally created by a C++ 开发者_如何转开发program. There is a date column, stored (it would appear) as time_t, i.e. Unix time, the nu

In a Delphi XE application, I am reading values from a database originally created by a C++ 开发者_如何转开发program. There is a date column, stored (it would appear) as time_t, i.e. Unix time, the number of seconds since 00:00, Jan 1, 1970 UTC. I can deal with the time zone, but how can I get TDateTime from (long) time_t?


Try using the unixtodatetime function which is part of the Dateutils unit : 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.

(But RRUZ answer should work and means you don't have to reinvent the wheel).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号