The ctime() function is defined in the time.h header file. Based on the given argument this function returns the string representing localtime.
char *ctime(const time_t *timer); #where timer should be a pointer
The ctime() function takes a single parameter 'timer' which is a pointer and it is used to set time_t object which contains a time value.
Parameter | Description | Required / Optional |
---|---|---|
timer | pointer to a time_t object that contains a calendar time | Required |
The function returns date and time information as a string in the format Www Mmm dd hh:mm:ss yyyy.
Input | Return Value |
---|---|
if parameter | calendar time |
#include <stdio.h>
#include <time.h>
int main()
{
time_t timer;
time(&timer;);
printf("The current time is %s", ctime(&timer;));
return(0);
}
Output:
The current time is Tue Aug 14 07:13:24 2012
#include <stdio.h>
#include <time.h>
int main (){
time_t D_time ;
time(& D_time);
clrscr();
printf("%s", ctime(& D_time));
}
Output:
Sat Sep 29 05:17:05 2018