Time.h

From Wikipedia, the free encyclopedia

C++ Standard Library headers
C Standard Library headers
assert.h
ctype.h
errno.h
float.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdarg.h
stddef.h
stdio.h
string.h
stdlib.h
time.h
The correct title of this article is time.h. The initial letter is shown capitalized due to technical restrictions.

time.h is a header file defined in the C Standard Library to provide standardized access to time functions.

[edit] Member functions

char *asctime(const tm* tmptr) Convert tm to a string in the format "Www Mmm dd hh:mm:ss yyyy", where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year. The string is followed by a newline and a terminating null character, conforming a total of 26 characters. The string pointed is statically allocated and shared by ctime and asctime functions. Each time one of these functions is called the content of the string is overwritten.
clock_t clock(void) Return number of clock ticks since process start.
char* ctime(const time_t* timer) Convert time_t value to string in the same format as asctime. The string pointed is statically allocated and shared by ctime and asctime functions. Each time one of these functions is called the content of the string is overwritten. ctime also uses internally the buffer used by gmtime and localtime as return value, so a call to this function will overwrite this.
double difftime(time_t timer2, time_t timer1) Returns the difference in seconds between the two times.
tm* gmtime(const time_t* timer) Convert time_t value to tm structure as UTC time. This structure is statically allocated and shared by gmtime, localtime and ctime functions. Each time one of these functions is called the content of the structure is overwritten.
tm* localtime(const time_t* timer) Convert time_t value to tm structure as local time. This structure is statically allocated and shared by gmtime, localtime and ctime functions. Each time one of these functions is called the content of the structure is overwritten.
time_t mktime(tm* ptm) Convert tm to time_t value. Checks the members of the tm structure passed as parameter ptm adjusting the values if the ones provided are not in the possible range or they are incomplete or mistaken and then translates that structure to a time_t value (seconds elapsed since Jan 1, 1970) that is returned. The original values of tm_wday and tm_yday members of ptm are ignored and filled with the correspondent ones to the calculated date. The range of tm_mday is not checked until tm_mon and tm_year are determined. On error, a -1 value is returned.
time_t time(time_t* timer) Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC from the system clock. Stores that value in timer. If timer is NULL, the value is not stored, but it is still returned by the function.
size_t strftime(char* s, size_t n, const char* format, const struct tm* tptr) Format a date/time string

[edit] Member constants

CLK_PER_SEC Constant that defines the number of clock ticks per second. Used by the clock() function.
CLOCKS_PER_SEC an alternative name for CLK_PER_SEC used in its place in some libraries
CLK_TICK Usually a macro for CLK_PER_SEC

[edit] Member types

clock_t Data type returned by clock(). Generally defined as long int.
time_t Data type returned by time(). Generally defined as long int.
tm
Members of tm Description
int   tm_hour hour (0 - 23)
int   tm_isdst daylight saving time enabled/disabled
int   tm_mday day of month (1 - 31)
int   tm_min minutes (0 - 59)
int   tm_mon month (0 - 11 : 0 = January)
int   tm_sec seconds (0 - 59)
int   tm_wday Day of week (0 - 6 : 0 = Sunday)
int   tm_yday Day of year (0 - 365)
int   tm_year Year less 1900
In other languages