1// Current date/time based on current system
2time_t now = time(0);
3
4// Convert now to tm struct for local timezone
5tm* localtm = localtime(&now);
6cout << "The local date and time is: " << asctime(localtm) << endl;
7
8// Convert now to tm struct for UTC
9tm* gmtm = gmtime(&now);
10if (gmtm != NULL) {
11cout << "The UTC date and time is: " << asctime(gmtm) << endl;
12}
13else {
14cerr << "Failed to get the UTC date and time" << endl;
15return EXIT_FAILURE;
16}
17