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 AngelScript.
In this AngelScript code, we use the <chrono> library to work with time. The std::chrono::system_clock::now() function is used to get the current time.
We then use duration_cast to convert the time to seconds, milliseconds, and nanoseconds since the Unix epoch.
To convert integer seconds or nanoseconds back to a time point, we use std::chrono::system_clock::from_time_t() and std::chrono::system_clock::time_point() respectively.
When you run this program, you’ll see output similar to this:
The exact numbers will depend on when you run the program.
Next, we’ll look at another time-related task: time parsing and formatting.