Pular para o conteúdo

Conheça Walt Disney World

C date and time functions

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

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 the epoch (which is usually the 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 the epoch to calendar time expressed as Universal Coordinated Time[2]
localtime converts time since the epoch to calendar time expressed as local time
mktime converts calendar time to time since the epoch
Constants CLOCKS_PER_SEC number of processor clock ticks per second
Types tm calendar time type
time_t time since the epoch type
clock_t process running time type

Example

The following C source code snippet prints the current time to the standard output stream.

#include <stdio.h>
#include <time.h>
 
int main()
{
    /* Obtain current time as seconds elapsed since the Epoch. */
    time_t clock = time(NULL);
 
    /* Convert to local time format and print to stdout. */
    printf("Current time is %s", ctime(&clock));
    return 0;
}

The output is:

Current time is Sat Dec 31 11:20:45 2011

References

External links

Personal tools
  • Create account
  • Log in
Namespaces

Variants
Actions
Navigation
Toolbox
Print/export