- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library function - ctime()
Description
The C library function char *ctime(const time_t *timer) returns a string representing the localtime based on the argument timer.
The returned string has the following format: Www Mmm dd hh:mm:ss yyyy, where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.
Declaration
Following is the declaration for ctime() function.
char *ctime(const time_t *timer)
Parameters
timer − This is the pointer to a time_t object that contains a calendar time.
Return Value
This function returns a C string containing the date and time information in a human-readable format.
Example
The following example shows the usage of ctime() function.
#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 that will produce the following result −
Current time = Mon Aug 13 08:23:14 2012
time_h.htm
Advertisements