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 
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;
	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));
	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 *