A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the Unix epoch. Here’s how to do it in Racket.
To run the program:
In Racket, we use current-seconds, current-milliseconds, and current-inexact-milliseconds to get the elapsed time since the Unix epoch in seconds and milliseconds. Racket doesn’t have a built-in function for nanoseconds, so we use current-inexact-milliseconds as the closest equivalent.
We can convert seconds back to a date object using the seconds->date function. Note that Racket’s date structure includes both date and time information.
Next, we’ll look at another time-related task: date parsing and formatting.