C date and time functions

From Wikipedia, the free encyclopedia
  (Redirected from Time())
Jump to: navigation, search

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

[edit] Overview of functions

The C date and time operations are defined in the time.h header file (ctime header in C++).

Identifier Description
Time
manipulation
difftime computes the difference between times
time returns the current time of the system as time since epoch (which is usually Unix epoch)
clock returns a processor tick count associated with the process
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

[edit] Example

This 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
*/

[edit] References

[edit] External links

Personal tools
Namespaces

Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages