function
<ctime>

ctime

char* ctime (const time_t * timer);
Convert time_t value to string
Interprets the value pointed by timer as a calendar time and converts it to a C-string containing a human-readable version of the corresponding time and date, in terms of local time.

The returned string has the following format:

Www Mmm dd hh:mm:ss yyyy


Where Www is the weekday, Mmm the month (in letters), dd the day of the month, hh:mm:ss the time, and yyyy the year.

The string is followed by a new-line character ('\n') and terminated with a null-character.

This function is equivalent to:
1
asctime(localtime(timer))

For an alternative with custom date formatting, see strftime.

Parameters

timer
Pointer to an object of type time_t that contains a time value.
time_t is an alias of a fundamental arithmetic type capable of representing times as returned by function time.

Return Value

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

The returned value points to an internal array whose validity or value may be altered by any subsequent call to asctime or ctime.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
/* ctime example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, time, ctime */

int main ()
{
  time_t rawtime;

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

  return 0;
}

Output:

The current local time is: Wed Feb 13 16:06:10 2013


Data races

The function accesses the object pointed by timer.
The function also accesses and modifies a shared internal buffer, which may cause data races on concurrent calls to asctime or ctime. Some libraries provide an alternative function that avoids this data race: ctime_r (non-portable).

Exceptions (C++)

No-throw guarantee: this function never throws exceptions.

See also