You can get the time using time_t now = time(NULL); or time(&now);
Then you usually convert to local time using struct tm *tm_now = localtime(&now); . A struct tm contains fields for year, month, day, day of the week, hour, minute and second. If you want to create print output, strftime supports this directly.
Both comply with C and C ++ standards, so they are available on most common platforms.
If you really only care about C ++, you can use std::put_time , which is similar to strftime , but a little easier to use for the typical case of writing output to a stream.
Jerry Coffin Jun 19 2018-12-12T00: 00Z
source share