How do i put time in my programs? Do you have to use time.h and what functions should i use?
Printable View
How do i put time in my programs? Do you have to use time.h and what functions should i use?
This code will initialize and return to the variable "Time" a pointer to a struct tm containing the current time. Just look in time.h and examine this "tm" structure to see what fields are there to extract.
Hope this helps.
Code:struct tm *Time;
time_t timenow;
time(&timenow);
Time = localtime(&timenow);
Code:
#include <time.h>
#include <iostream.h>
int main(void)
{
time_t t = time(NULL); //calls time function
cout << ctime(&t) << endl; //display of time
}