I am trying to use the DateTimeToUnix function in Delphi 5. DateTimeToUnix uses DateUtils (Which wasn't introduced until Delphi 6 according to some information found on the web); following this logic I ascertain that Delphi 5 does not support this function.
A question similar to this was asked on stackoverflow and marked as a duplicate, however; there was nothing mentioned about Delphi 5 in the answers.
Original Question: https://stackoverflow.com/questions/27885090/delphi-5-how-to-get-current-time-now-in-unix-timestamp?lq=1
I believe The code found at the following website answers mine and the original question: http://www.swissdelphicenter.com/torry/showcode.php?id=844
unit Unix_Utils;
interface
Uses SysUtils;
function DateTimeToUnix(ConvDate: TDateTime): Longint;
function UnixToDateTime(USec: Longint): TDateTime;
implementation
const UnixStartDate: TDateTime = 25569.0; // Sets UnixStartDate to TDateTime of 01/01/1970
function DateTimeToUnix(ConvDate: TDateTime): Longint;
begin
//example: DateTimeToUnix(now);
Result := Round((ConvDate - UnixStartDate) * 86400);
end;
function UnixToDateTime(USec: Longint): TDateTime;
begin
//Example: UnixToDateTime(1003187418);
Result := (Usec / 86400) + UnixStartDate;
end;
end.
Thomas Greiner is the author of the original code. "The above code has been modified from its original version. It has been formatted to fit the screen"
Steps to use the above code in Delphi 5:
- File > New... > New Tab > Unit > OK
- Replace the entire contents of the new unit with the code shown above
- Save the new unit "unix_utils" somewhere like C:\Program Files\Borland\Delphi5\Lib\
- If DateTimeToUnix is ever needed: Project > Add to Project... > browse to unix_utils > Then click open
- I believe if unix_utils file is saved in the aforementioned location it can just be added to the "Uses" section of a unit???
So is this a duplicate?