Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Io

🎈 🎈 🎈
+1

    # Convert Unix timestamp to Date
    unixTimestamp := 1027580913
    date := Date fromSeconds(unixTimestamp)
    
    writeln("Converted Date: ", date asString)            
        

Output:
Converted Date: 2002-07-25 07:08:33
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of Unix timestamp to date conversion using Io, the Unix timestamp '1027580913' (representing a date in 2020) is converted to a Date object using the Date fromSeconds method.
The result is a human-readable Date object, which is then printed using asString. The output will be the corresponding date, '2002-07-25 07:08:33'.



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