Home >>C Time Library Function >C ctime() function

C ctime() function

C ctime() function

The C time ctime() function is used to return a string representing the localtime based on the argument timer. It converts the given time since epoch to a calendar local time and then to a character representation. The format of the returned string is as following: Www Mmm dd hh:mm:ss yyyy. It is defined in <time.h> header file.

Syntax:

char *ctime(const time_t *timer)

timer − It is the pointer to a time_t object that contains a calendar time.

Here is an example of ctime() function:


#include <stdio.h>
#include <time.h>
int main () 
{
time_t curtime;
time(&curtime);
printf("Current time = %s", ctime(&curtime));
return(0);
}

Output:
Current time = Tue Apr 14 08:50:39 2020

No Sidebar ads