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