C Programming/time.h

In C programming language time.h (used as ctime in C++) is a header file defined in the C Standard Library that contains time and date function declarations to provide standardized access to time/date manipulation and formatting.

Functions

 * Convert  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, containing a total of 26 characters. The string pointed at is statically allocated and shared by   and   functions. Each time one of these functions is called the contents of the string is overwritten.
 * Convert  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, containing a total of 26 characters. The string pointed at is statically allocated and shared by   and   functions. Each time one of these functions is called the contents of the string is overwritten.


 * Return number of clock ticks since process start.
 * Return number of clock ticks since process start.


 * Convert  time value to string in the same format as  . The string pointed is statically allocated and shared by   and   functions. Each time one of these functions is called the content of the string is overwritten.   also uses internally the buffer used by   and   as return value, so a call to this function will overwrite this.
 * Convert  time value to string in the same format as  . The string pointed is statically allocated and shared by   and   functions. Each time one of these functions is called the content of the string is overwritten.   also uses internally the buffer used by   and   as return value, so a call to this function will overwrite this.


 * Returns timer2 minus timer1 to give the difference in seconds between the two times.
 * Returns timer2 minus timer1 to give the difference in seconds between the two times.


 * Convert a  value to a tm structure as UTC time. This structure is statically allocated and shared by ,   and   functions. Each time one of these functions is called the content of the structure is overwritten.
 * Convert a  value to a tm structure as UTC time. This structure is statically allocated and shared by ,   and   functions. Each time one of these functions is called the content of the structure is overwritten.


 * Convert a  value to a tm structure as UTC time. The time is stored in the tm struct referred to by result. This function is the thread-safe version of.
 * Convert a  value to a tm structure as UTC time. The time is stored in the tm struct referred to by result. This function is the thread-safe version of.


 * Convert a  time value to a tm structure as local time (ie time adjusted for the local time zone and daylight savings). This structure is statically allocated and shared by ,   and   functions. Each time one of these functions is called the content of the structure is overwritten.
 * Convert a  time value to a tm structure as local time (ie time adjusted for the local time zone and daylight savings). This structure is statically allocated and shared by ,   and   functions. Each time one of these functions is called the content of the structure is overwritten.


 * Convert  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 a 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.
 * Convert  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 a 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 in . If   is null, the value is not stored, but it is still returned by the function.
 * Get the current time (number of seconds from the epoch) from the system clock. Stores that value in . If   is null, the value is not stored, but it is still returned by the function.


 * Format  into a date/time string.
 * Format  into a date/time string.


 * Scan values from  string into   struct. On success it returns pointer to the character following the last character parsed. Otherwise it returns null.
 * Scan values from  string into   struct. On success it returns pointer to the character following the last character parsed. Otherwise it returns null.


 * timegm is functionally identical to mktime except it always takes the input values to be Coordinated Universal Time (UTC) regardless of any local time zone setting. Note that timegm is the inverse of gmtime.
 * Portability note: mktime is essentially universally available. timegm is rather rare. For the most portable (but non-thread safe) conversion from a UTC broken-down time to a simple time, set the TZ environment variable to UTC, call mktime, then set TZ back.
 * Portability note: mktime is essentially universally available. timegm is rather rare. For the most portable (but non-thread safe) conversion from a UTC broken-down time to a simple time, set the TZ environment variable to UTC, call mktime, then set TZ back.

Unix extensions
The Single UNIX Specification (IEEE 1003.1, formerly POSIX) adds two functions to :  and. These are reentrant versions of  and. Both functions require the caller to provide a buffer in which to store the textual representation of a moment in time. The following sample demonstrates, how to use the reentrant version of localtime and asctime:

Since these functions are not in the C++ standard, they do not belong to the namespace  in that language. 

Constants

 * Constant that defines the number of clock ticks per second. Used by the clock function.
 * Constant that defines the number of clock ticks per second. Used by the clock function.


 * An alternative name for CLK_PER_SEC used in its place in some libraries.
 * An alternative name for CLK_PER_SEC used in its place in some libraries.


 * Obsolete macro for CLK_PER_SEC.
 * Obsolete macro for CLK_PER_SEC.

Data types

 * Data type returned by clock. Generally defined as int or long int.
 * Data type returned by clock. Generally defined as int or long int.


 * Data type returned by time. Generally defined as int or long int.
 * Data type returned by time. Generally defined as int or long int.


 * A "broken-down" (componentized) calendar representation of time.
 * A "broken-down" (componentized) calendar representation of time.

Calendar time
Calendar time (also known as "broken-down time") in the C standard library is represented as the    structure, consisting of the following members:

Examples
This source code snippet prints the current time to the standard output stream.