ctime function returns a time in string

Syntax

C ctime function has the following syntax.

char *ctime(const time_t *time);

C ctime function is from header file time.h.

Description

C ctime function returns a time in string, whose form is

day month year hours:minutes:seconds year \n\0

Example

Use C ctime function to get time in string.


#include <time.h>
#include <stdio.h>
/*www.  ja  v  a 2s  . c  o  m*/
int main(void)
{
  time_t lt;

  lt = time(NULL);
  printf(ctime(&lt));

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h