C Reference function asctime()

Usage of asctime():

char * asctime ( const struct tm * ptr_time );

Parameters:

ptr_time is a pointer to a tm structure which in turn 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’) and the terminating null-character.

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.

Explanation:

The function asctime() interprets the contents of the tm structure as calendar time and converts it to a string. The returned string contains a human-readable version of the date and time. 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 asctime():


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

int main ()
{
	time_t  time_raw_format;
	struct tm * ptr_time;

	time ( &time_raw_format);
	ptr_time = localtime ( &time_raw_format );
	printf ( "The current date and time is: %s", asctime(ptr_time));

	return 0;
}

Output example of the program above:


	The current date and time is: Fri Jan 11 11:59:51 2008

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.

There is currently one response to “C Reference function asctime()”

Why not let us know what you think by adding your own comment!

  1. hema on January 8th, 2012:

    THANK YOU SO MUCH THESE INFO WILL BE VERY USE FULL DO MY PROJECT…