C Library Functions -ctime()

C Standard Library - <time.h>

Description

C Library Functionschar *ctime(const time_t *timer)Returns a string representing the local time, which is based on the parametertimer。

The format of the returned string is as follows:Www Mmm dd hh:mm:ss yyyywhere,WwwIndicates the day of the week,MmmIt is the month represented by letters,ddIt indicates the day of the month,hh:mm:ssrepresents time,yyyyrepresents the year.

Declaration

The following is the declaration of the ctime() function.

char *ctime(const time_t *timer)

Parameter

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

Return Value

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

Example

The following example demonstrates the usage of the ctime() function.

Example

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

Let us compile and run the above program, which will produce the following result:

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

C Standard Library - <time.h>

other extensions