C gmtime()

The gmtime() function returns a pointer to the broken-down form of time in the form of a tm structure. The time is represented in Coordinated Universal Time (UTC), which is essentially Greenwich mean time. The time pointer is usually obtained through a call to time(). If the system does not support Coordinated Universal Time, NULL is returned.

The structure used by gmtime() 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.

gmtime() Syntax

Following is the syntax of the gmtime() function :

struct tm *gmtime(const time_t *time);

gmtime() Example

Following program prints both the local time and the UTC of the system :

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

C Online Test

« Previous Function Next Function »

Follow/Like Us on Facebook

Subscribe Us on YouTube