Latest web development tutorials

C library functions - ctime ()

C standard library - <time.h> C standard library - <time.h>

description

C library functionschar * ctime (const time_t * timer ) Returns a string representation of local time, local time is based on the parameter timer.

Returns a string formatted asfollows: Www Mmm dd hh: mm: ss yyyywhere,Www day of theweek,Mmm is amonth-letter,dd represents the day of themonth,hh: mm: ss representstime,yyyy It represents the year.

statement

Here is ctime () function's declaration.

char *ctime(const time_t *timer)

parameter

  • timer - This is a pointer to a pointer time_t object, the object contains a calendar time.

return value

This function returns a C string that contains the date and time information in a readable format.

Examples

The following example demonstrates the ctime () function is used.

#include <stdio.h>
#include <time.h>

int main ()
{
   time_t curtime;

   time(&curtime);

   printf("当前时间 = %s", ctime(&curtime));

   return(0);
}

Let's compile and run the above program, which will result in the following:

当前时间 = Mon Aug 13 08:23:14 2012

C standard library - <time.h> C standard library - <time.h>