C asctime()


The asctime() function returns a pointer to a string that contains the information stored in the structure pointed to by ptr converted into the following form :

day month date hours:minutes:seconds year\n\0

For example:

Fri Apr 15 12:05:34 2005

The structure pointed to by ptr is usually obtained from either localtime() or gmtime().

The buffer used by asctime() to hold the formatted output string is a statically allocated character array and is overwritten each time the function is called. If you wish to save the contents of the string, you must copy it elsewhere.

asctime() Syntax

Following is the syntax of the asctime() function :

char *asctime(const struct tm *ptr);

asctime() Example

Following program displays the local time defined by the system :

void main()
	struct tm *ptr;
	time_t lt;
	lt = time(NULL);
	ptr = localtime(&lt);

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋