简体   繁体   中英

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. 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. I can deal with the time zone, but how can I get TDateTime from (long) time_t?

尝试使用作为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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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