# C Time Function

Home > Lesson > Chapter 22
5 Steps - 3 Clicks

# C Time Function

### Description

By using C Time Function, there is a possibility of setting the date and time. C inherits the properties of functions and structures from C- library and exhibits the settings of date and time. The header file required to set date and time in C is <time.h>. Mainly, there are four C Time Function types. They are: The first three terms acts as functions and helps in showing the time and date in the form of integer. Some of the functions included in C standard libraries are given in the below table.
Functions Description
time_t time(time_t *time); Returns local time by converting time_t using pointer
char *ctime(const time_t *time); Returns local time by converting time_t using pointer
struct tm *localtime(const time_t *time); Returns to tm structure using pointer to represent local time
clock_t clock(void) Returns duration of current running program
char * asctime(const struct tm * time); Returns pointer to structure converting the data to day month date hours:minutes:seconds:year\n\0 format
struct tm * gmtime(const time_t *time); Returns pointer to structure representing the GMT time
time_t mktime(struct tm *time); Returns the exact time in the structure when pointer points it.
double difftime(time_t time2, time_t time1); Calculates the differences between time1 and time2
size_t strftime(); Returns formatted date and time
The last term 'tm' will be in structure format which consists of following elements.
Field Type Meaning Range
tm_sec int represents seconds of minutes 0-61
tm_min int represents minutes of hour 0-59
tm_hour int represents hours of day 0-23
tm_mday int represents day of month 1-31
tm_mon int represents month of year from January 0-11
tm_year int represents years since 1900
tm_wday int represents days since Sunday 0-6
tm_yday int represents days since January 1st 0-365
tm_isdst int represents hours saving day time