Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ctime, ctime64 - Date and time (CET)

&pagelevel(4)&pagelevel

Definition

#include <time.h>

char *ctime(const time_t *sec_ptr);
char *ctime64(const time64_t *sec_ptr);

ctime and ctime64 interpret the time specification to which sec_ptr points (see return
values of mktime, mktime64 and time, time64) as the number of seconds which have
passed since the reference date (epoch). The functions calculate the local time (CET) from
this and convert the result to a string. ctime and ctime64 behave analogously to
localtime and localtime64.

Negative values are interpreted as seconds before the reference date. The earliest
displayable date with ctime is 12/13/1901 20:45:52 and with ctime64 01/01/1900
00:00:00 local time.
By default, the reference date is always 1/1/1970 00:00:00.

The latest date which can be displayed with ctime is 01/19/2038 03:14:07 or 3/18/4317
02:44:48 with ctime64.

Return val.

Pointer to the 26-character string generated.

The resulting string has a length of 26 (incl. the terminating null byte \0) and
is formatted as a date and time of the form:
Weekday Month Day Hrs:Min:Sec Year,
e.g. Thu Jun 14 15:20:54 2018\n\0

NULL

In the event of an error

Notes

The asctime, ctime, ctime64, gmtime, gmtime64, localtime and localtime64
functions write their result into the same internal C data area. This means that each of these
function calls overwrites the previous result of any of the other functions.

Time specifications are based on the 24-hour clock.

Example

The following program converts an input value to local time and outputs the result in the
form of a date and time.

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

See also

asctime, gmtime, gmtime64, localtime, localtime64, mktime, mktime64, time, time64