Recently, when writing a PE analysis tool, you need to convert the timedatestamp field value to the datetime format, which is the source code of Delphi.
// Converts the number of seconds in GMT to the date and time format.
Function getgmtdatetime (value: int64): tdatetime;
VaR
Year, month, day: word;
Hour, Min, SEC, msec: word;
Iyear, iday: word;
Ihour, Imin, ISEC: word;
RINT, I: integer;
Tempdate, temptime: tdatetime;
Begin
// GMT is calculated from January 1, January 1, 1970, so it is used as the initial value.
Year: = 1970; month: = 1; Day: = 1;
Hour: = 0; min: = 0; sec: = 0; msec: = 0;
// Calculate the year when the file is created
Iyear: = value Div (365*24*60*60 );
Year: = year + iyear;
// How many days does the computing file have besides creating the entire year?
Iday: = (value Mod (365*24*60*60) Div (24*60*60 );
// Calculate the number of copies per year in a leap year
RINT: = 0;
For I: = 1970 to year-1 do
Begin
If (I mod 4) = 0 then
RINT: = RINT + 1;
End;
// Computing File Creation Time (when)
Ihour: = (value Mod (365*24*60*60) mod (24*60*60) Div (60*60 );
Hour: = hour + ihour;
// Calculate the file creation time (in minutes)
Imin: = (value Mod (365*24*60*60) mod (24*60*60) mod (60*60) Div 60;
Min: = min + Imin;
// Computing File Creation Time (several seconds)
ISEC: = (value Mod (365*24*60*60) mod (24*60*60) mod (60*60) mod 60;
SEC: = sec + ISEC;
// Merge Date and Time
Tempdate: = encodedate (year, month, day );
Temptime: = encodetime (hour, Min, SEC, msec );
// Because there are 29 days in February of a leap year and 365 days in a year of a leap year, and days in a year of the same year
// It is calculated by 365. Therefore, we need to subtract one day from the leap year.
// The final return value merges the date and time into the tdatetime type.
Result: = (tempdate + iday-RINT) + temptime;
End;
Procedure tform1.button1click (Sender: tobject );
VaR
Temp: tdatetime;
Begin
// 708992537 is the number of seconds
Temp: = getgmtdatetime (708992537 );
// Retrieve the date
Edit1.text: = datetostr (temp );
// Fetch time
Edit2.text: = timetostr (temp );
End;