Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Racket

🎈 🎈 🎈
+1

    #lang racket

    ; Convert Unix timestamp to Date
    (define unix-timestamp 1524818363) 
    (define date (seconds->date unix-timestamp))
    
    ; Format and display the date
    (printf "Converted Date: ~a-~a-~a ~a:~a:~a\n"
            (date-year date)
            (date-month date)
            (date-day date)
            (date-hour date)
            (date-minute date)
            (date-second date))            
        

Output:
Converted Date: 2015-02-24 22:52:43
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example, the Unix timestamp 1524818363 is converted into a date structure using the seconds->date function. The date structure contains fields like year, month, day, hour, minute, and second, which are accessed using functions like date-year, date-month, and others.
The result, 2018-04-27 08:39:23, is printed using printf.



Other useful Racket date functions

Function Description Example
seconds->date Converts a Unix timestamp to a date structure. (seconds->date 1514764800) returns 2018-01-01 00:00:00
date->seconds Converts a date structure to a Unix timestamp. (date->seconds (date 2018 7 15 12 30 45 0 0 0)) returns 1531656645
current-seconds Returns the current Unix timestamp. (current-seconds) returns the current Unix timestamp.
date Creates a date structure with the given year, month, day, hour, minute, second, etc. (date 2018 7 15 12 30 45 0 0 0) creates the date 2018-07-15 12:30:45
date-year Extracts the year from a date structure. (date-year (seconds->date 1514764800)) returns 2018
date-month Extracts the month from a date structure. (date-month (seconds->date 1514764800)) returns 1 (January)
date-day Extracts the day of the month from a date structure. (date-day (seconds->date 1514764800)) returns 1
date-hour Extracts the hour from a date structure. (date-hour (seconds->date 1514764800)) returns 0
date-minute Extracts the minute from a date structure. (date-minute (seconds->date 1514764800)) returns 0
date-second Extracts the second from a date structure. (date-second (seconds->date 1514764800)) returns 0
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