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 Lua.
To run the program:
Note that Lua doesn’t have built-in functions for milliseconds or nanoseconds since the epoch. We use os.clock() to get a high-resolution time difference, which we then use to approximate milliseconds and nanoseconds. The accuracy may not be as precise as in other languages with dedicated functions for these purposes.
Next, we’ll look at another time-related task: time parsing and formatting.