Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in Pascal

How to convert Unix timestamp to Datetime in Pascal

🎈 🎈 🎈
+1

    program UnixTimestampToDate;

    uses
        SysUtils, DateUtils;
    
    var
        unixTimestamp: Int64;
        dateTime: TDateTime;
    
    begin
        unixTimestamp := 1299363331;  // Unix timestamp
        dateTime := UnixToDateTime(unixTimestamp);
        WriteLn('Converted Date: ', DateTimeToStr(dateTime));
    end.            
        

Output:
Converted Date: 2011-03-05 22:15:31
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of Unix timestmap to date conversion in Pascal, the Unix timestamp 1299363331 is used inside the UnixToDateTime function from the DateUtils unit. This function converts the Unix timestamp to a TDateTime object, which represents the date and time in Pascal. The result is then printed using DateTimeToStr to convert it into a human-readable string.
The output in this example is 2011-03-05 22:15:31.



Other useful Pascal date functions

Function Description Example
Now() Returns the current date and time as a TDateTime object. Now() returns 15/05/2020 08:10:45
UnixToDateTime() Converts a Unix timestamp to a TDateTime object. UnixToDateTime(1589530245) returns 15/05/2020 08:10:45
DateTimeToUnix() Converts a TDateTime object to a Unix timestamp. DateTimeToUnix(EncodeDateTime(2020, 5, 15, 8, 30, 45, 0)) returns 1589530245
EncodeDateTime() Creates a TDateTime object from individual year, month, day, hour, minute, second, and millisecond values. EncodeDateTime(2020, 5, 15, 8, 30, 45, 0) returns 15/05/2020 08:10:45
DateTimeToStr() Converts a TDateTime object to a string in a human-readable format. DateTimeToStr(UnixToDateTime(1589530245)) returns 15/05/2020 08:10:45
StrToDateTime() Converts a string representing a date and time to a TDateTime object. StrToDateTime('15/05/2020 08:10:45') returns a TDateTime object.
FormatDateTime() Formats a TDateTime object according to a specified format string. FormatDateTime('yyyy-mm-dd hh:nn:ss', Now()) returns 2020-05-15 08:10:45
DecodeDate() Extracts the year, month, and day from a TDateTime object. DecodeDate(UnixToDateTime(1589530245), year, month, day)
DecodeTime() Extracts the hour, minute, second, and millisecond from a TDateTime object. DecodeTime(UnixToDateTime(1589530245), hour, min, sec, msec)
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder