Export (0) Print
Expand All
div
eof
Expand Minimize

_strtime, _wstrtime

Copy the time to a buffer. More secure versions of these functions are available; see _strtime_s, _wstrtime_s.

char *_strtime(
   char *timestr 
);
wchar_t *_wstrtime(
   wchar_t *timestr 
);
template <size_t size>
char *_strtime(
   char (&timestr)[size]
); // C++ only
template <size_t size>
wchar_t *_wstrtime(
   wchar_t (&timestr)[size]
); // C++ only

timestr

Time string.

Returns a pointer to the resulting character string timestr.

The _strtime function copies the current local time into the buffer pointed to by timestr. The time is formatted as hh:mm:ss where hh is two digits representing the hour in 24-hour notation, mm is two digits representing the minutes past the hour, and ss is two digits representing seconds. For example, the string 18:23:44 represents 23 minutes and 44 seconds past 6 P.M. The buffer must be at least 9 bytes long.

_wstrtime is a wide-character version of _strtime; the argument and return value of _wstrtime are wide-character strings. These functions behave identically otherwise.If timestr is NULL pointer or if timestr is formatted incorrectly, the invalid parameter handler is invoked, as described in Parameter Validation. If the exception is allowed to continue, these functions return a NULL and set errno to EINVAL if timestr was a NULL or set errno to ERANGE if timestr is formatted incorrectly.

In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. For more information, see Secure Template Overloads.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined

_tstrtime

_strtime

_strtime

_wstrtime

Routine

Required header

_strtime

<time.h>

_wstrtime

<time.h> or <wchar.h>

For additional compatibility information, see Compatibility in the Introduction.

// crt_strtime.c
// compile with: /W3

#include <time.h>
#include <stdio.h>

int main( void )
{
   char tbuffer [9];
   _strtime( tbuffer ); // C4996
   // Note: _strtime is deprecated; consider using _strtime_s instead
   printf( "The current time is %s \n", tbuffer );
}
The current time is 14:21:44
Show:
© 2014 Microsoft