C library function - ctime()
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
- timer -- This is a pointer to a time_t object containing a calendar time.
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 -