time.h Header File in C Programming

The header file as ‘time.h’ is used to declare date and time functions which are primarily used to access date/time for manipulations.

Some of the standard member functions of time.h header files are,

_________________________________________________________________
Function Name	Description
_________________________________________________________________
asctime -	Returns string : day month date hours:min:sec year
clock -	        Returns time if exists otherwise -1.
ctime -	        Returns current time.
difftime -	Returns the difference in seconds between two 
                times.
gmtime -	Returns the Greenwitch Mean Time (GMT) / UTC.
localtime -	It returns local time.
_________________________________________________________________

Program :

/*  Program to demonstrate time.h header file working.
Creation Date : 06 Nov 2010 02:36:27 PM
Author : www.technoexam.com [Technowell, Sangli] */

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

int main(void)
{
	struct tm, *lcl;
	time_t t1;
	clrscr();
	t1 = time(NULL);
	lcl = localtime(&t1);
	printf("\n\tLocal Date and Time: %s",asctime(lcl));
	lcl = gmtime(&t1);
	printf("\n\n\tUTC Date and Time: %s",asctime(lcl));
	getch();
	return 0;
}

Output :

	Local Date and Time : Sat Nov 06 14:36:27 2010

	UTC Date and Time : Sat Nov 06 19:36:27 2010_

Leave A Comment

Your email address will not be published. Required fields are marked *