Hey Guys ,
The Following Code is Just for Displaying time..
Can Someone Tell me what
time_t t does?
and time(&t) means?
And why there is ctime(&t) in printf?
Code:main(){
time_t t;
time(&t);
printf("Today's date and time : %s",ctime(&t));
}
Printable View
Hey Guys ,
The Following Code is Just for Displaying time..
Can Someone Tell me what
time_t t does?
and time(&t) means?
And why there is ctime(&t) in printf?
Code:main(){
time_t t;
time(&t);
printf("Today's date and time : %s",ctime(&t));
}
Where did you get this code from? If that source does not contain an explanation, I'd suggest you do a search for "time.h" tutorials. Also, looking up the functions you're uncertain about is a good way to get more information on what they do.
time_t
The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard <time.h> header.
Reference:
https://en.wikibooks.org/wiki/C_Prog.../time.h/time_t
Code to get system date and time:
Code:
Code:int main()
{
time_t T= time(NULL);
struct tm tm = *localtime(&T);
printf("System Date is: %02d/%02d/%04d\n",tm.tm_mday, tm.tm_mon+1, tm.tm_year+1900);
printf("System Time is: %02d:%02d:%02d\n",tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0;
}
Reference:
http://www.includehelp.com/c-programs/system-date-time-linux.aspx