Crystal offers extensive support for times and durations; here are some examples.
When you run this program, you’ll see output similar to the following:
Note that the exact output will vary based on the current time when you run the program.
In Crystal, the Time struct is used to represent a moment in time. It provides methods for creating, manipulating, and formatting times. The Time::Span struct represents a duration of time.
Crystal’s Time API is quite similar to other languages, making it easy to work with dates and times in your programs.
Next, we’ll look at the related idea of time relative to the Unix epoch.