codescracker


c

C localtime()



« Previous Function Next Function »


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 :

#include<time.h>
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 :

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

/* Print local and UTC time. */

void main()
{
	clrscr();
	
	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));
	
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test