1. time(0) function
? ? in the ctime header file, returns the current time in seconds elapsed since the time 00:00:00 on January 1, 1970 GMT, ?which is known as the UNIX epoch because 1970 was the year when the UNIX operating system was formally introduced.
?
a sample code from Introduction to Programming with C++
?
#include <iostream> #include <ctime> using namespace std; int main(){ // Obtain the total seconds since the midnight, Jan 1, 1970 int totalSeconds = time(0); // Compute the current second in the minute in the hour int currentSecond = totalSeconds % 60; // Obtain the total minutes int totalMinutes = totalSeconds / 60; // Compute the current minute in the hour int currentMinute = totalMinutes % 60; // Obtain the total hours long totalHours = totalMinutes / 60; // Compute the current hour int currentHour = (int)( totalHours % 24 ); // Display the results cout << "Current time is " << currentHour << " : " << currentMinute << " : " << currentSecond << " GMT " << endl; return 0; }