Time.h
Encyclopedia
C date and time functions refer to a group of functions in the standard library
C standard library
The C Standard Library is the standard library for the programming language C, as specified in the ANSI C standard.. It was developed at the same time as the C POSIX library, which is basically a superset of it...

 of the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 implementing date and time manipulation operations. They provide support for time acquisition, conversion between date formats and formatted output to strings.

Function overview

The C date and time operations are defined in the time.h header file
Header file
Some programming languages use header files. These files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers...

 (ctime header in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

).
Time manipulation
difftime - computes the difference between times
time - returns the current time of the system as time since epoch
clock - returns raw processor clock time since the program is started

Format conversions
asctime - converts a tm object to a textual representation
ctime - converts a tm object to a textual representation
strftime - converts a tm object to custom textual representation
wcsftime - converts a tm object to custom wide string textual representation
gmtime - converts time since epoch to calendar time expressed as Universal Coordinated Time
localtime - converts time since epoch to calendar time expressed as local time
mktime - converts calendar time to time since epoch

Constants
CLOCKS_PER_SEC - number of processor clock ticks per second

Types
tm - calendar time type
time_t - time since epoch type
clock_t - process running time

Example

This source code snippet prints the current time to the standard output stream.
  1. include
  2. include


int main(void)
{
time_t timer = time(NULL);
printf("current time is %s", ctime(&timer));
return 0;
}

/*
Output is:
current time is Mon Oct 24 17:57:45 2011
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK