- Time.h
In the C and C++ programming languages, time.h (
ctime is the recommended header file for C++ programs) is aheader file defined in theC Standard Library to declare time and date functions that provide standardized access to time/date manipulation and formatting.Functions
;
char *asctime(
: Convertconst struct tm* tmptr)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 anewline and a terminatingnull character , containing a total of 26 characters. The string pointed at is statically allocated and shared byctime
andasctime
functions. Each time one of these functions is called the contents of the string is overwritten.;clock_t clock(void)
: Return number of clock ticks since process start.;char* ctime(
: Convertconst time_t* timer)
time value to string in the same format astime_t asctime
. The string pointed is statically allocated and shared byctime
andasctime
functions. Each time one of these functions is called the content of the string is overwritten.ctime
also uses internally the buffer used bygmtime
andlocaltime
as return value, so a call to this function will overwrite this.;double difftime(
: Returns the difference in seconds between the two times.;time_t timer2,time_t timer1)
: Convert astruct tm* gmtime(const time_t* timer)
value to a tm structure as UTC time. This structure is statically allocated and shared bytime_t gmtime
,localtime
andctime
functions. Each time one of these functions is called the content of the structure is overwritten.;
: Convert astruct tm* localtime(const time_t* timer)
time value to a tm structure as local time. This structure is statically allocated and shared bytime_t gmtime
,localtime
andctime
functions. Each time one of these functions is called the content of the structure is overwritten.;
: Converttime_t mktime(struct tm* ptm)tm
to a
time 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 atime_t time_t value 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.;
: Get the current time (number of seconds from the epoch) from the system clock. Stores that value intime_t time(time_t* timer)timer
. Iftimer
is null, the value is not stored, but it is still returned by the function.;
: Formatsize_t strftime(char* s,size_t n,const char* format,const struct tm* tptr)tm
into a date/time stringConstants
;
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_TCK
: Obsolete macro for CLK_PER_SEC.Data types
;
clock_t
: Data type returned by clock().
Generally defined as long int.;
: Data type returned by time().time_t
Generally defined as long int.;
: A non-linear, broken-down calendar representation of time.struct tmCalendar time
Calendar time in the C standard library is represented as the
structure, consisting of the following attributes:struct tmReferences
*
*
Wikimedia Foundation. 2010.