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 is not 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 |
.NET Framework equivalent |
---|---|---|
Convert time from type struct tm to character string. The versions of these functions with the _s suffix are more secure. |
System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString |
|
Return elapsed wall-clock time for process. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
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. |
System::DateTime::GetDateTimeFormats, System::DateTime::ToString, System::DateTime::ToLongTimeString, System::DateTime::ToShortTimeString |
Compute difference between two times. |
||
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. |
||
Set modification time on open file |
System::IO::File::SetLastAccessTime, System::IO::File::SetLastWriteTime, System::IO::File::SetCreationTime |
|
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 tmwith local correction. The versions of these functions with the _s suffix are more secure. |
|
Convert time to calendar value in Greenwich Mean Time. |
||
Convert time to calendar value. |
System::DateTime::DateTime |
|
Return current system date as string. The versions of these functions with the _s suffix are more secure. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
Format date-and-time string for international use. |
System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString |
|
Return current system time as string. The versions of these functions with the _s suffix are more secure. |
System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString |
|
Get current system time as type time_t, __time32_t or as type __time64_t. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
Set external time variables from environment time variable TZ. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
|
Set modification time for specified file using either current time or time value stored in structure. |
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples. |
Hinweis
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.
Hinweis
In versions of Visual C++ and Microsoft C/C++ before Visual C++ 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
Reference
Change History
Date |
History |
Reason |
---|---|---|
December 2010 |
Corrected the .NET equivalent of _strdate, _wstrdate, _strdate_s, _wstrdate_s. |
Content bug fix. |