C Time Functions - C ctime

Converts a time value to string in the same format as asctime.


char* ctime (const time_t * timer);


This function has the following parameter.

Pointer to an object of type time_t that contains a time value.


C string containing the date and time information in a human-readable format.

The resulting string has the following format: Www Mmm dd hh:mm:ss yyyy

  • Www - the day of the week (one of Mon, Tue, Wed, Thu, Fri, Sat, Sun).
  • Mmm - the month (one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
  • dd - the day of the month
  • hh - hours
  • mm - minutes
  • ss - seconds
  • yyyy - years


#include <stdio.h> /* printf */
#include <time.h> /* time_t, time, ctime */
/* w w w  . j  a v  a  2  s .c o m*/
int main ()
  time_t rawtime;

  time (&rawtime);
  printf ("The current local time is: %s", ctime (&rawtime));

  return 0;


The code above generates the following result.

Example 2

#include <time.h>
#include <stdio.h>
int main(void)
    time_t result = time(NULL);
    printf("%s", ctime(&result));

The code above generates the following result.