C Standard Library |
---|
|
C date and time functions refer to a group of functions in the standard library of the C programming language implementing date and time manipulation operations.[1] They provide support for time acquisition, conversion between date formats and formatted output to strings.
Contents |
The C date and time operations are defined in the time.h
header file (ctime
header in C++).
difftime
- computes the difference between timestime
- returns the current time of the system as time since epoch (which is usually Unix epoch)clock
- returns raw processor clock time since the program is startedasctime
- converts a tm
object to a textual representationctime
- converts a tm
object to a textual representationstrftime
- converts a tm
object to custom textual representationwcsftime
- converts a tm
object to custom wide string textual representationgmtime
- converts time since epoch to calendar time expressed as Universal Coordinated Timelocaltime
- converts time since epoch to calendar time expressed as local timemktime
- converts calendar time to time since epochCLOCKS_PER_SEC
- number of processor clock ticks per secondtm
- calendar time typetime_t
- time since epoch typeclock_t
- process running timeThis source code snippet prints the current time to the standard output stream.
#include <stdio.h> #include <time.h> int main(void) { time_t timer = time(NULL); printf("current time is %s", ctime(&timer)); return 0; } /* Output is: current time is Sat Dec 31 11:20:45 2011 */