_strdate_wstrdate

将当前系统日期复制到缓冲区。 提供这些函数的更安全版本;请参阅 _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

参数

datestr
指向包含格式化日期字符串的缓冲区的指针。

返回值

这些函数均返回指向结果字符串 datestr 的指针。

备注

提供这些函数的更安全版本;请参阅 _strdate_s_wstrdate_s。 建议尽可能使用更为安全的函数。

_strdate 函数将当前系统日期复制到 datestr 所指向的缓冲区,格式为 mm/dd/yy,其中 mm 表示两位数字的月份,dd 表示两位数字的日期,yy 表示年份的最后两位数字。 例如,字符串 12/05/99 表示 1999 年 12 月 5 日。 缓冲区长度必须至少为 9 个字节。

如果 datestrNULL 指针,则调用无效参数处理程序,如参数验证中所述。 如果允许继续执行,则这些函数返回 -1 并将 errno 设置为 EINVAL

_wstrdate_strdate 的宽字符版本;_wstrdate 的参数和返回值都是宽字符字符串。 否则这些函数具有相同行为。

在 C++ 中,这些函数具有模板重载,以调用这些函数的更新、更安全副本。 有关详细信息,请参阅安全模板重载

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

一般文本例程映射

TCHAR.H 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_tstrdate _strdate _strdate _wstrdate

要求

例程 必需的标头
_strdate <time.h>
_wstrdate <time.h> 或 <wchar.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// 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.
    //
    _tzset();

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

另请参阅

工时管理
asctime_wasctime
ctime_ctime32_ctime64_wctime_wctime32_wctime64
gmtime_gmtime32_gmtime64
localtime_localtime32_localtime64
mktime_mktime32_mktime64
time_time32_time64
_tzset