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 Cilk.
In this Cilk program, we use the std::chrono library to work with time. The std::chrono::system_clock::now() function is used to get the current time.
We can then use duration_cast to convert the time to seconds, milliseconds, or nanoseconds since the Unix epoch.
To convert integer seconds or nanoseconds since the epoch into the corresponding time point, we can create a std::chrono::system_clock::time_point with the desired duration.
When you compile and 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.