Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Xojo

🎈 🎈 🎈
+1

    Var unixTimestamp As Double = 1090555421

    // Convert Unix timestamp to DateTime
    Var date As DateTime = DateTime.FromSecondsSince1970(unixTimestamp)
    
    // Format the date to a readable string
    Var formattedDate As String = date.ToString("yyyy-MM-dd HH:mm:ss")
    
    // Output the formatted date
    System.DebugLog("Converted Date: " + formattedDate)            
        

Output:
Converted Date 2004-07-23 04:03:41
Example only. There may be multiple ways to perform this operation.

Code Explanation

To convert a Unix timestamp to date in Xojo DateTime.FromSecondsSince1970(unixTimestamp) converts the Unix timestamp 1090555421 into a DateTime object. The ToString("yyyy-MM-dd HH:mm:ss") method is used to format the DateTime object as a readable string with year, month, day, hour, minute, and second. Subsequently the result 2004-07-23 04:03:41 is output to the debug log.


Other useful Xojo date functions (DateTime API)

Function Description Example
DateTime.FromSecondsSince1970() Creates a DateTime object from a Unix timestamp (seconds since 1970-01-01). DateTime.FromSecondsSince1970(1514764800) returns 2018-01-01 00:00:00
DateTime.SecondsFrom1970 Returns the Unix timestamp for a given DateTime object. date.SecondsFrom1970 returns 1531656645
DateTime.Now Returns the current date and time as a DateTime object. DateTime.Now returns the current date and time.
DateTime.ToString() Formats a DateTime object as a string according to a specified format. date.ToString("yyyy-MM-dd HH:mm:ss") returns 2018-07-15 12:30:45
New DateTime() Creates a DateTime object with the specified date and time. New DateTime(2018, 7, 15, 12, 30, 45) creates the 2018-07-15 12:30:45 date.
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