C time.h library functions: The C time.h library function defines four variable types, two macro and various functions for manipulating date and time.
C time.h library function
Library Variables
Variables |
Description |
size_t |
It is the unsigned integral type and is the result of the size of the keyword |
clock_t( ) |
This is a type suitable for storing the processor time |
time_t |
This is a type suitable for storing the calendar time. |
struct tm |
This is a structure used to hold the time and date |
Example
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
Macro |
Description |
NULL |
macro is the value of a null pointer constant |
CLOCLKS_PER_SEC |
Macro represents the number of processor clocks per second |
Library Functions
Function |
Description |
char *asctime(const struct tm *timeptr) |
Returns a pointer to a string which represents the day and time of the structure timeptr |
clock_t clock(void) |
Returns the processor clock time used since the beginning of an implementation-defined era |
char *ctime(const time_t *timer |
Returns a string representing the localtime based on the argument timer |
double difftime(time_t time1, time_t time2) |
Returns the difference of seconds between time1 and time2 (time1-time2) |
struct tm *gmtime(const time_t *timer) |
The value of the timer is broken up into the structure tm and expressed in Coordinated Universal Time (UTC) also known as Greenwich Mean Time (GMT) |
struct tm *local time(const time_t *timer) |
The value of the timer is broken up into the structure tm and expressed in the local time zone |
time_t mktime(struct tm *timeptr) |
It converts the structure pointed to by timeptr into a time_t value according to the local time zone |
size_t strftime(char *str, size_t max size, const char *format, const struct tm *timeptr) |
Formats the time represented in the structure timeptr according to the formatting rules defined in format and stored into str |
time_t time(time_t *timer) |
It calculates the current calendar time and encodes it into time_t format. |