Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Io

🎈 🎈 🎈
+1

    # Convert Date to Unix timestamp
    date := Date clone setYear(2014) setMonth(4) setDay(25) setHour(0) setMinute(25) setSecond(33)
    unixTimestamp := date secondsSince(Date fromString("1970-01-01"))
    
    writeln("Unix Timestamp: ", unixTimestamp)            
        

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

Code Explanation

In this example of date to Unix timestamp conversion using Io, a Date object is created for '2014-04-25 00:25:33' using the setYear, setMonth, setDay, and other methods.
The secondsSince method calculates the number of seconds between the given Date object and January 1, 1970 (Unix epoch), which returns the Unix timestamp. The result is '1398385533', which is printed.



Other useful Io date functions

Function Description Example
Date now() Returns the current date and time as a Date object. Date now() returns 2024-08-28 12:34:56
Date fromSeconds() Creates a Date object from a Unix timestamp (seconds since 1970). Date fromSeconds(1589530245) returns 2020-05-15 08:10:45
secondsSince() Returns the number of seconds since a given Date object. date secondsSince(Date fromString("1970-01-01")) returns 1589530245
Date setYear() Sets the year for the Date object. date setYear(2020) sets the year to 2020.
Date setMonth() Sets the month for the Date object (1 for January). date setMonth(5) sets the month to May.
Date setDay() Sets the day of the month for the Date object. date setDay(15) sets the day to the 15th.
Date setHour() Sets the hour for the Date object. date setHour(8) sets the hour to 8 AM.
Date setMinute() Sets the minutes for the Date object. date setMinute(30) sets the minutes to 30.
Date setSecond() Sets the seconds for the Date object. date setSecond(45) sets the seconds to 45.
Date asString() Returns the Date object as a string. date asString() returns a formatted date string, such as 2020-05-15 08:10:45.
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