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.
Function |
Use |
.NET Framework equivalent |
---|---|---|
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. |
System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString |
clock |
Return elapsed CPU 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 |
difftime, _difftime32, _difftime64 |
Compute difference between two times. |
System::DateTime::Subtract |
_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. |
System::DateTime::Now |
_futime, _futime32, _futime64 |
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. |
System::DateTime::UtcNow, System::DateTime::ToUniversalTime |
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. |
System::DateTime::ToLocalTime |
_mkgmtime, _mkgmtime32, _mkgmtime64 |
Convert time to calendar value in Greenwich Mean Time. |
System::DateTime::ToUniversalTime |
mktime, _mktime32, _mktime64 |
Convert time to calendar value. |
System::DateTime::DateTime |
_strdate, _wstrdate, _strdate_s, _wstrdate_s |
Return current system date as string. The versions of these functions with the _s suffix are more secure. |
System::DateTime::Parse |
strftime, wcsftime, _strftime_l, _wcsftime_l |
Format date-and-time string for international use. |
System::DateTime::ToLongDateString, System::DateTime::ToLongTimeString, System::DateTime::ToShortDateString, System::DateTime::ToShortTimeString, System::DateTime::ToString |
_strtime, _wstrtime, _strtime_s, _wstrtime_s |
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 |
time, _time32, _time64 |
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. |
_tzset |
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. |
_utime, _utime32, _utime64, _wutime, _wutime32, _wutime64 |
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. |
Note: |
---|
In all versions of Microsoft C/C++ except Microsoft C/C++ version 7.0, and in all versions of Microsoft Visual C++ 2005, 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 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. In Visual C++ 2005, time_t is 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. |