Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Xojo

🎈 🎈 🎈
+1

    // Create a DateTime object for 2024-01-13 19:32:16
    Var date As New DateTime(2024, 1, 13, 19, 32, 16)
    
    // Convert DateTime to Unix timestamp
    Var unixTimestamp As Double = date.SecondsFrom1970
    
    // Output the Unix timestamp
    System.DebugLog("Unix Timestamp: " + unixTimestamp.ToString)            
        

Output:
Unix Timestamp: 1705174336
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this date to Unix timestamp conversion using Xojo, the DateTime object is initialized with the date '2024-01-13 19:32:16'.
The SecondsFrom1970 property of the DateTime class returns the Unix timestamp (i.e., the number of seconds since January 1, 1970) and the result 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