C programming time.h header


The C time.h header defines two macros and several types to manipulate date and time in our program.This header mainly deals with the calendar time(the Gregorian calendar).Some functions deal with local time,the time in your specific area and Daylight Saving Time.All the macros , types and functions declared under this header is given below.

Macro

NULLThe value null
CLOCKS_PER_SECA constant value of type clock_t.Use this value to divide the value obtained by calling clock() to obtain the number of seconds elapsed used by CPU.

Types

size_t -An ‘unsigned int’ type.

clock_t -An arithmetic type returned by clock() function.

time_t -An arithmetic type returned by the functions timer() and mktime() functions.

struct tm -The members of this structure holds the values that represent time , date , hour , minute , seconds and so on.All the members of this structure are listed below.

tm_secHolds the seconds value– [0,60]
tm_minHolds the minute value –[0,59]
tm_hourHolds the hours — [0,23]
tm_mdayDay of the month –[1,31]
tm_monMonths since January –[0,11]
tm_yearYears since 1900
tm_wdayWeek days [Sunday,Saturday]– [0,6]
tm_ydayDays since January 1- [0,365]
tm_isdstDaylight saving time flag

The value of ‘tm_isdst’ is +ve if the Daylight Saving Time is in effect,0(zero) if Daylight Saving Time is not in effect,negative if the information is not available.


Functions

Return
type
Function name and
argument
Function definition
Time manipulation
clock_tclock(void)Determines the processor time used.
doubledifftime(time_t time1, time_t time0)Compute the time difference.
time_tmktime(struct tm *timeptr)converts the broken-down time,expressed as local time
time_ttime(time_t *timer)Determines the current calendar time
Time conversion
char*asctime(const struct tm *timeptr) converts the broken-down time into string.
char*ctime(const time_t *timer)converts the calendar time into string.
struct tm*gmtime(const time_t *timer)converts the calendar time to string as UTC.
struct tm*localtime(const time_t *timer)Converts the calendar time to string as local time.
size_tstrftime(char * restrict s,
size_t maxsize ,
const char * restrict format ,
const struct tm * restrict timeptr)
Generate a string that holds the date and time in the format we want using conversion specifier.