Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in Racket

🎈 🎈 🎈
+1

    #lang racket

    ; Convert Date to Unix timestamp
    (define my-date (date 2024 2 28 8 45 22 0 0 0))
    (define unix-timestamp (date->seconds my-date))
    
    ; Display the Unix timestamp
    (printf "Unix Timestamp: ~a\n" unix-timestamp)            
        

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

Code Explanation

In this Racket example, the date function is used to create a date structure for the date '2024-02-28 08:45:22'. This date structure is then converted to a Unix timestamp using date->seconds.
The Unix timestamp is then printed using the printf function.


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