Bewerken

Delen via


Time management

Use these functions to get the current time and convert, adjust, and store it as necessary. The current time is the system time.

The _ftime and localtime routines use the TZ environment variable. If TZ isn't set, the run-time library attempts to use the time-zone information specified by the operating system. If this information is unavailable, these functions use the default value of PST8PDT. For more information on TZ, see _tzset; also see _daylight, timezone, and _tzname.

Time routines

Function Use
asctime, _wasctime, asctime_s, _wasctime_s Convert time from type struct tm to character string. The versions of these functions with the _s suffix are more secure.
clock Return elapsed wall-clock time for process.
ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64, _ctime_s, _ctime32_s, _ctime64_s, _wctime_s, _wctime32_s, _wctime64_s Convert time from type time_t, __time32_t or __time64_t to character string. The versions of these functions with the _s suffix are more secure.
difftime, _difftime32, _difftime64 Compute difference between two times.
_ftime, _ftime32, _ftime64,_ftime_s, _ftime32_s, _ftime64_s Store current system time in variable of type struct _timeb or type struct __timeb64 The versions of these functions with the _s suffix are more secure.
_futime, _futime32, _futime64 Set modification time on open file
gmtime, _gmtime32, _gmtime64, gmtime_s, _gmtime32_s, _gmtime64_s Convert time from type time_t to struct tm or from type __time64_t to struct tm. The versions of these functions with the _s suffix are more secure.
localtime, _localtime32, _localtime64, localtime_s, _localtime32_s, _localtime64_s Convert time from type time_t to struct tm or from type __time64_t to struct tm with local correction. The versions of these functions with the _s suffix are more secure.
_mkgmtime, _mkgmtime32, _mkgmtime64 Convert time to calendar value in Greenwich Mean Time.
mktime, _mktime32, _mktime64 Convert time to calendar value.
_strdate, _wstrdate, _strdate_s, _wstrdate_s Return current system date as string. The versions of these functions with the _s suffix are more secure.
strftime, wcsftime, _strftime_l, _wcsftime_l Format date-and-time string for international use.
_strtime, _wstrtime, _strtime_s, _wstrtime_s Return current system time as string. The versions of these functions with the _s suffix are more secure.
time, _time32, _time64 Get current system time as type time_t, __time32_t or as type __time64_t.
_tzset Set external time variables from environment time variable TZ.
_utime, _utime32, _utime64, _wutime, _wutime32, _wutime64 Set modification time for specified file using either current time or time value stored in structure.

Note

In all versions of Microsoft C/C++ except Microsoft C/C++ version 7.0, and in all versions of Visual C++, the time function returns the current time as the number of seconds elapsed since midnight on January 1, 1970. In Microsoft C/C++ version 7.0, time returned the current time as the number of seconds elapsed since midnight on December 31, 1899.

Note

In versions of Visual C++ and Microsoft C/C++ before Visual Studio 2005, time_t was a long int (32 bits) and hence could not be used for dates past 3:14:07 January 19, 2038, UTC. time_t is now equivalent to __time64_t by default, but defining _USE_32BIT_TIME_T changes time_t to __time32_t and forces many time functions to call versions that take the 32-bit time_t. For more information, see Standard types and comments in the documentation for the individual time functions.

See also

Universal C runtime routines by category