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 Idris.
We use epochTime from the Data.Time module to get the current time as seconds since the Unix epoch.
To get milliseconds and nanoseconds, we multiply the seconds by 1000 and 1000000000 respectively. Note that Idris doesn’t have built-in functions for milliseconds and nanoseconds like some other languages, so we’re performing the calculations manually.
You can also convert integer seconds or nanoseconds since the epoch into the corresponding DateTime.
To run the program, save it as Epoch.idr and use the Idris compiler:
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.