Standard library header <ctime> - cppreference.com

From cppreference.com

This header was originally in the C standard library as

<time.h>

.

This header is part of the

C-style date and time

library.

Macro constants

CLOCKS_PER_SEC

number of processor clock ticks per second
(macro constant)

[edit]

NULL

implementation-defined null pointer constant
(macro constant)

[edit]

Types

clock_t

process running time
(typedef)

[edit]

size_t

unsigned integer type returned by the

sizeof

operator
(typedef)

[edit]

time_t

time since epoch type
(typedef)

[edit]

tm

calendar time type
(class)

[edit]

timespec

(C++17)

time in seconds and nanoseconds
(struct)

[edit]

Functions

Time manipulation

clock

returns raw processor clock time since the program is started
(function)

[edit]

time

returns the current time of the system as time since epoch
(function)

[edit]

difftime

computes the difference between times
(function)

[edit]

timespec_get

(C++17)

returns the calendar time in seconds and nanoseconds based on a given time base
(function)

[edit]

timespec_getres

(C++26)

returns the resolution of calendar time based on a given time base
(function)

[edit]

Format conversions

asctime

(deprecated in C++26)

converts a

std::tm

object to a textual representation
(function)

[edit]

ctime

(deprecated in C++26)

converts a

std::time_t

object to a textual representation
(function)

[edit]

strftime

converts a

std::tm

object to custom textual representation
(function)

[edit]

gmtimegmtime_r

(C++26)

converts time since epoch to calendar time expressed as Universal Coordinated Time
(function)

[edit]

localtimelocaltime_r

(C++26)

converts time since epoch to calendar time expressed as local time
(function)

[edit]

mktime

converts calendar time to time since epoch
(function)

[edit]

timegm

(C++26)

converts calendar time to time since epoch, ignoring the Daylight Saving Time flag
(function)

[edit]

Synopsis

#define __STDC_VERSION_TIME_H__ 202311L#define NULL /* implementation-defined */#define CLOCKS_PER_SEC /* see description */#define TIME_UTC /* see description */#define TIME_MONOTONIC /* see description */// optional#define TIME_ACTIVE /* see description */// optional#define TIME_THREAD_ACTIVE /* see description */// optionalnamespacestd{usingsize_t=/* implementation-defined */;usingclock_t=/* see description */;usingtime_t=/* see description */;structtimespec;structtm;clock_tclock();doubledifftime(time_ttime1,time_ttime0);time_tmktime(tm*timeptr);time_ttimegm(tm*timeptr);time_ttime(time_t*timer);inttimespec_get(timespec*ts,intbase);inttimespec_getres(timespec*ts,intbase);// char* asctime(const tm* timeptr);// char* ctime(const time_t* timer);tm*gmtime(consttime_t*timer);tm*gmtime_r(consttime_t*timer,tm*buf);tm*localtime(consttime_t*timer);tm*localtime_r(consttime_t*timer,tm*buf);size_tstrftime(char*s,size_tmaxsize,constchar*format,consttm*timeptr);}Class

std::timespec

structtimespec{std::time_ttv_sec;longtv_nsec;};Class

std::tm

structtm{inttm_sec;inttm_min;inttm_hour;inttm_mday;inttm_mon;inttm_year;inttm_wday;inttm_yday;inttm_isdst;};