Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - ctime()

C library function - ctime()

C Standard Library - <time.h> C Standard Library -

Description

C library function **char ctime(const time_t timer) Returns a string representing local time, based on the argument timer.

The format of the returned string is as follows: Www Mmm dd hh:mm:ss yyyy WhereWww represents the day of the week,Mmm is the month in letters,dd represents the day of the month,hh:mm:ss represents the time,yyyy represents the year.

Declaration

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



char *ctime(const time_t *timer)

Parameters

Return Value

The function returns a C string containing date and time information in a human-readable format.

Example

The following example demonstrates the use 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's compile and run the above program, which will produce the following result:



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

C Standard Library - <time.h> C Standard Library -