Required header: #include
<time.h>
A computer executes instructions at a very steady rate of
time -- once every clock tick.
We will be using the time( ) function which utilizes
a new data type: time_t.
time_t rightNow;
// defines a time
variable
time(NULL)
returns the number of seconds elapsed since 00:00:00 hours, GMT (Greenwich
Mean Time),
January 1, 1970.
Example:
#include<iostream.h>
#include<time.h>
int main(void)
{
time_t getTime; //declare a time variable
called getTime
getTime = time(NULL); //get seconds
cout<<"The
number of seconds since 1-1-1970: "
<< getTime;
return 0;
}
Screen:
The number of seconds since 1-1-1970: 85430133124
(Number will change with
each run!!) |
|