Exportar (0) Imprimir
Expandir todo
div
eof
Expandir Minimizar

_strdate_s, _wstrdate_s

Copy the current system date to a buffer. These are versions of _strdate, _wstrdate with security enhancements as described in Security Enhancements in the CRT.


errno_t _strdate_s(
   char *buffer,
   size_t sizeInBytes
);
errno_t _wstrdate_s(
   wchar_t *buffer,
   size_t sizeInWords
);
template <size_t size>
errno_t _strdate_s(
   char (&buffer)[size]
); // C++ only
template <size_t size>
errno_t _wstrdate_s(
   wchar_t (&buffer)[size]
); // C++ only

Parameters

[out] buffer

A pointer to a buffer which will be filled in with the formatted date string.

[in] sizeInBytes

Size of the buffer in bytes when using the ANSI version of the function.

[in] sizeInWords

Size of the datestr in words when using the Unicode version of the function.

Zero if successful. The return value is an error code if there is a failure. Error codes are defined in ERRNO.H; see table below for the exact errors generated by this function. For more information on error codes, see errno.

buffer sizeInBytes/ sizeInWords Return Contents of buffer

NULL

(any)

EINVAL

Not modified

Not NULL (pointing to valid buffer)

0

EINVAL

Not modified

Not NULL (pointing to valid buffer)

0 < size < 9

EINVAL

Empty string

Not NULL (pointing to valid buffer)

Size > 9

0

Current date formatted as specified in the remarks

Passing in an invalid non NULL value for the buffer will result in an access violation if the size parameter is greater than 9.

Passing values for size that is greater than the actual size of the buffer will result in buffer overrun.

These functions provide more secure versions of _strdate and _wstrdate. The _strdate_s function copies the current system date to the buffer pointed to by buffer, 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. For example, the string 12/05/99 represents December 5, 1999. The buffer must be at least 9 bytes long.

_wstrdate_s is a wide-character version of _strdate_s; the argument and return value of _wstrdate_s are wide-character strings. These functions behave identically otherwise.

If buffer is a NULL pointer, or if sizeInBytes or sizeInWords is less than 9 characters, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return -1 and set errno to EINVAL if the buffer is NULL or if sizeInBytes or sizeInWords is less than or equal to 0, or set errno to ERANGE if sizeInBytes or sizeInWords is less than 9.

In C++, using these functions is simplified by template overloads; the overloads can infer buffer length automatically (eliminating the need to specify a size argument) and they can automatically replace older, non-secure functions with their newer, secure counterparts. For more information, see Secure Template Overloads.

Generic-Text Routine Mapping:
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined

_tstrdate_s

_strdate_s

_strdate_s

_wstrdate_s

Routine Required header Compatibility

_strdate

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wstrdate

<time.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

See the example for time.

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft