C localtime()

The localtime() function returns a pointer to the broken-down form of time in the form of a tm structure. The time is represented in local time. The time pointer is usually obtained through a call to time().

The structure used by localtime() to hold the broken-down time is statically allocated and is overwritten each time the function is called. If you wish to save the contents of the structure, you must copy it elsewhere.

localtime() Syntax

Following is the syntax of the localtime() function :

struct tm *localtime(const time_t *time);

localtime() Example

Following program prints both the local time and the Coordinated Universal Time (UTC) of the system :


/* Print local and UTC time. */

void main()
	struct tm *local;
	time_t t;
	t = time(NULL);
	local = localtime(&t);
	printf("Local time and date: %s\n", asctime(local));
	local = gmtime(&t);
	printf("UTC time and date: %s\n", asctime(local));

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋