_strdate, _wstrdate_strdate, _wstrdate

将当前系统日期复制到缓冲区。Copy current system date to a buffer. 这些函数的更安全版本已发布,请参阅 _strdate_s、_wstrdate_sMore secure versions of these functions are available; see _strdate_s, _wstrdate_s.


char *_strdate(
   char *datestr
wchar_t *_wstrdate(
   wchar_t *datestr
template <size_t size>
char *_strdate(
   char (&datestr)[size]
); // C++ only
template <size_t size>
wchar_t *_wstrdate(
   wchar_t (&datestr)[size]
); // C++ only


指向包含格式化日期字符串的缓冲区的指针。A pointer to a buffer containing the formatted date string.

返回值Return Value

每个函数返回指向结果字符串的指针datestrEach of these functions returns a pointer to the resulting character string datestr.


这些函数的更安全版本已发布,请参阅 _strdate_s、_wstrdate_sMore secure versions of these functions are available; see _strdate_s, _wstrdate_s. 建议尽可能使用更为安全的函数。It is recommended that the more secure functions be used wherever possible.

_Strdate函数将当前系统日期复制到由指向的缓冲区datestr格式化mm/dd / yy,其中mm是两位数表示月dd是两位数表示日,和yy是一年中的最后两位数字。The _strdate function copies the current system date to the buffer pointed to by datestr, formatted mm/dd/yy, where mm is two digits representing the month, dd is two digits representing the day, and yy is the last two digits of the year. 例如,字符串12/05/99表示 1999 年 12 月 5 日。For example, the string 12/05/99 represents December 5, 1999. 缓冲区长度必须至少为 9 个字节。The buffer must be at least 9 bytes long.

如果datestrNULL调用指针,无效参数处理程序,如中所述参数验证If datestr is a NULL pointer, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,这些函数将返回-1 并设置errnoEINVALIf execution is allowed to continue, these functions return -1 and set errno to EINVAL.

_wstrdate是宽字符版本 _strdate; 的自变量和返回值 _wstrdate都是宽字符字符串。_wstrdate is a wide-character version of _strdate; the argument and return value of _wstrdate are wide-character strings. 否则这些函数具有相同行为。These functions behave identically otherwise.

在 C++ 中,这些函数具有模板重载,以调用这些函数的更新、更安全副本。In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. 有关详细信息,请参阅 Secure Template OverloadsFor more information, see Secure Template Overloads.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_tstrdate_tstrdate _strdate_strdate _strdate_strdate _wstrdate_wstrdate


例程所返回的值Routine 必需的标头Required header
_strdate_strdate <time.h><time.h>
_wstrdate_wstrdate <time.h> 或 <wchar.h><time.h> or <wchar.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.


// strdate.c
// compile with: /W3
#include <time.h>
#include <stdio.h>
int main()
    char tmpbuf[9];

    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value
    // for the variable.

    printf( "OS date: %s\n", _strdate(tmpbuf) ); // C4996
    // Note: _strdate is deprecated; consider using _strdate_s instead
OS date: 04/25/03

请参阅See also

时间管理Time Management
asctime、_wasctimeasctime, _wasctime
ctime、_ctime32、_ctime64、_wctime、_wctime32、_wctime64ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64
gmtime、_gmtime32、_gmtime64gmtime, _gmtime32, _gmtime64
localtime、_localtime32、_localtime64localtime, _localtime32, _localtime64
mktime、_mktime32、_mktime64mktime, _mktime32, _mktime64
time、_time32、_time64time, _time32, _time64