#include using namespace std; #include // for time_t, time(), ctime() void main() { // The time_t data type is really an int in this version of the operating system. time_t ttStartTime = time(NULL); cout << "Current time: " << long(ttStartTime) << endl; system("pause"); // Allow a program user to wait a few seconds before proceeding. cout << "\nCurrent time: " << long(time(NULL)) << endl; // Now what time is it? // Calculate and display the elpase time (single line of code) cout << "Elapse (calculated in-line):" << long(time(NULL)-ttStartTime) << endl; system("pause"); // Allow a program user to wait a few seconds before proceeding. // Alternative: Calculate and display the elpase time (3 lines of code). time_t ttCurrentTime = time(NULL); long lElapseTime = long(ttCurrentTime - ttStartTime); cout << "\nElapse (calculated separately):" << lElapseTime << endl; system("pause"); // Allow a program user to wait a few seconds before proceeding. cout << "\nWant to make millions in consulting work . . . \n"; system("pause"); // Allow a program user to wait a few seconds before proceeding. // THE END OF TIME // The following code sets a 32-bit integer to the largest possible signed value. // I used hex assignment (0x7FFFFFFF) to make it clearer that we have (in binary) // a 0 followed by 31 1's. // - 0x7 --> 0111 // - 0xF --> 1111 // - 0xF --> 1111 // - 0xF --> 1111 // - 0xF --> 1111 // - 0xF --> 1111 // - 0xF --> 1111 // - 0xF --> 1111 // The beginning of time as we know it . . . // Thu Jan 1 00:00:00 1970 (GMT) time_t ttSmallestSignedInt = 0x00000000; // hexadecimal value (decimal 0) cout << "\nThe Beginning of Time: " << ctime( & ttSmallestSignedInt); // The end of time as we know it . . . // Mon Jan 18 22:14:07 2038 (Eastern Standard Time) . . . // The next second is invalid. time_t ttLargestSignedInt = 0x7FFFFFFF; // hexadecimal value (decimal 2,147,483,647) cout << "\nThe End of Time: " << ctime( & ttLargestSignedInt); }