C Reference function ctime()

Usage of ctime():

char * ctime ( const time_t * ptr_time );


Pointer ptr_time to a time_t object that contains a calendar time.

Return Value:

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

The string is followed by a new-line character (‘\n’) Converts the time_t object pointed by timer to a C string containing a human-readable version of the corresponding local time and date.

The functions ctime and asctime share the array which holds this string. If either one of these functions is called, the content of the array is overwritten.


The string that is returned will have the following format:

	Www Mmm dd hh:mm:ss yyyy

Www = which day of the week.

Mmm = month in letters.

dd = the day of the month.

hh:mm:ss = the time in hour, minutes, seconds.

yyyy = the year.

Source code example of ctime():

#include <stdio.h>
#include <time.h>

int main ()
	time_t time_raw_format;

	time ( &time_raw_format );
	printf ( "The current local time: %s", ctime(&time_raw_format));

	return 0;

Output example of the program above:

	The current local time: Fri Jan 11 12:09:51 2008

Note: this function is equivalent to: asctime(localtime(timer)).

This entry was posted in C Reference time.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.