C programming ctime time.h


char *ctime(const time_t *timer);

Parameters:
timer -A time_t type storing the seconds elapsed since 1900.

Return type
char -Returns the pointer returned by the ‘asctime’ function with that broken-down time as argument.

In C programming the <time.h> ctime function converts the calendar time pointed to by ‘timer’ to local time in the form of a string given below.

Thu Sep 16 10:03:52 2013\n\0

Note here the ‘timer’ stores the number of seconds elapsed since 1st January 1900,the function ‘ctime’ converts the seconds into the time format string as shown above.

Code example

time_t t;

time( &t ); //get the current time

printf( “%s” , ctime(&t) );

Output,

Thu Jul 20 22:25:31 2017

The output given is the time when the program is executed.

Link : C time time.h


*Side Note

The function ‘ctime’ is equivalent to calling,

asctime(localtime(timer));


Related links

->C asctime time.h

->C mktime time.h