Easy Tutorial
❮ C Function Memmove C Enum ❯

C Standard Library - <time.h>

Introduction

The time.h header file defines four variable types, two macros, and various functions for manipulating date and time.

Library Variables

The following variable types are defined in the time.h header file:

No. Variable & Description
1 size_t <br> This is an unsigned integer type, which is the result of the sizeof keyword.
2 clock_t <br> This is a type suitable for storing processor time.
3 time_t is <br> This is a type suitable for storing calendar time.
4 struct tm <br> This is a structure to hold time and date.

The definition of the tm structure is as follows:

struct tm {
   int tm_sec;         /* seconds, range 0 to 59        */
   int tm_min;         /* minutes, range 0 to 59        */
   int tm_hour;        /* hours, range 0 to 23        */
   int tm_mday;        /* day of the month, range 1 to 31    */
   int tm_mon;         /* month, range 0 to 11        */
   int tm_year;        /* The number of years since 1900    */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365    */
   int tm_isdst;       /* Daylight saving time        */
};

Library Macros

The following macros are defined in the time.h header file:

No. Macro & Description
1 NULL <br> This macro is the value of a null pointer constant.
2 CLOCKS_PER_SEC <br> This macro represents the number of processor clocks per second.

Library Functions

The following functions are defined in the time.h header file:

No. Function & Description
1 char *asctime(const struct tm *timeptr) <br> Returns a pointer to a string that represents the day and time of the structure timeptr.
2 clock_t clock(void) <br> Returns the processor time consumed by the program since the beginning (usually the start of the program).
3 char *ctime(const time_t *timer) <br> Returns a string representing the local time based on the timer parameter.
4 double difftime(time_t time1, time_t time2) <br> Returns the difference in seconds between time1 and time2 (time1-time2).
5 struct tm *gmtime(const time_t *timer) <br> The value of timer is broken down into the tm structure, represented in Coordinated Universal Time (UTC), also known as Greenwich Mean Time (GMT).
6 struct tm *localtime(const time_t *timer) <br> The value of timer is broken down into the tm structure, represented in the local time zone.
7 time_t mktime(struct tm *timeptr) <br> Converts the structure pointed to by timeptr into a time_t value according to the local time zone.
8 size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr) <br> Formats the time represented in the structure timeptr according to the formatting rules defined in format, and stores the result in str.
9 time_t time(time_t *timer) <br> Calculates the current calendar time and encodes it into time_t format.
❮ C Function Memmove C Enum ❯