Here’s the translated code and explanation in Ada, formatted in Markdown suitable for Hugo:
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 Ada.
In this Ada program, we use the Ada.Calendar package to work with time. The Clock function gives us the current time.
To get the seconds, milliseconds, and nanoseconds since the Unix epoch, we calculate the difference between the current time and the Unix epoch (January 1, 1970). We use the Seconds function to get the integral part of the seconds, and Sub_Second to get the fractional part.
We can also convert integer seconds or nanoseconds since the epoch back into the corresponding Time value by adding the duration to the epoch time.
To compile and run this Ada program:
Note that the exact output will depend on when you run the program.
Next, we’ll look at another time-related task: time parsing and formatting.