Ada offers extensive support for times and durations; here are some examples.
To run the program, save it as time_example.adb and use the Ada compiler (e.g., GNAT):
This will output the current time, the specified time (2009-11-17 20:34:58), and various time calculations and comparisons.
Note that Ada’s standard library provides robust time handling capabilities, but the exact output format might differ from what’s shown in the original example. The Ada.Calendar and Ada.Calendar.Formatting packages offer extensive functionality for working with dates and times.
Ada doesn’t have a direct equivalent to Go’s nanosecond precision or Location type, but it does provide time zone support through Ada.Calendar.Time_Zones. The examples here use UTC implicitly.
Remember that Ada is strongly typed, so some conversions between types (like Time to String) require explicit Image or formatting functions.
Next, we’ll look at the related idea of time relative to the Unix epoch, although Ada doesn’t have a built-in concept of “Unix time” in its standard library.