Easy Tutorial
❮ C Exercise Example100 C Exercise Example72 ❯

C Library Function - ctime()

C Standard Library - <time.h>

Description

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

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

Declaration

Here is the declaration for the ctime() function.

char *ctime(const time_t *timer)

Parameters

Return Value

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

Example

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

#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:

Current time = Mon Aug 13 08:23:14 2012

C Standard Library - <time.h>

❮ C Exercise Example100 C Exercise Example72 ❯