Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Scheme

🎈 🎈 🎈
+1

    (import (srfi 19))

    (define unix-timestamp 1325712621) 
    (define date (seconds->date unix-timestamp))
    
    (display (date->string date))
    (newline)            
        

Output:
2012-01-04 21:30:21
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this Scheme snippet for converting a Unix timestamp to a date, the Unix timestamp '1514764800' is converted to a human-readable date using the seconds->date function from SRFI-19.
This function takes the Unix timestamp in seconds and converts it to a date structure. The date->string function formats the date as a string, eg 2012-01-04 21:30:21, which is printed using display.


Other useful Scheme date functions (SRFI-19)

Function Description Example
seconds->date Converts a Unix timestamp (in seconds) to a date structure. (seconds->date 1514764800) returns 2018-01-01 00:00:00+00:00
date->seconds Converts a date structure to a Unix timestamp. (date->seconds (make-date 0 30 12 15 7 2018 0)) returns 1531656600
make-date Creates a date structure from second, minute, hour, day, month, year, and time zone components. (make-date 0 30 12 15 7 2018 0) creates the date 2018-07-15 12:30:00.
date->string Converts a date structure to a formatted string. (date->string date) returns a formatted string like 2018-07-15 12:30:00+00:00.
current-date Returns the current date as a date structure. (current-date) returns the current date and time.
date-year Extracts the year from a date structure. (date-year (current-date)) returns the current year.
date-month Extracts the month from a date structure. (date-month (current-date)) returns the current month.
date-day Extracts the day of the month from a date structure. (date-day (current-date)) returns the current day of the month.
date-hour Extracts the hour from a date structure. (date-hour (current-date)) returns the current hour.
date-minute Extracts the minute from a date structure. (date-minute (current-date)) returns the current minute.
date-second Extracts the second from a date structure. (date-second (current-date)) returns the current second.
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