_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

这些函数均返回指向结果字符串 datestr 的指针。Each 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 并将 errno 设置为 EINVALIf 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 _strdate _strdate _wstrdate


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

有关其他兼容性信息,请参见“简介”中的 兼容性For additional compatibility information, see Compatibility in the Introduction.


// 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、_wasctime asctime, _wasctime
ctime、_ctime32、_ctime64、_wctime、_wctime32、_wctime64 ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64
gmtime、_gmtime32、_gmtime64 gmtime, _gmtime32, _gmtime64
localtime、_localtime32、_localtime64 localtime, _localtime32, _localtime64
mktime、_mktime32、_mktime64 mktime, _mktime32, _mktime64
time、_time32、_time64 time, _time32, _time64