Udostępnij za pośrednictwem


_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

Parameters

  • timestr
    Time string.

Return Value

Returns a pointer to the resulting character string timestr.

Remarks

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

Requirements

Routine

Required header

_strtime

<time.h>

_wstrtime

<time.h> or <wchar.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

// 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

.NET Framework Equivalent

See Also

Reference

Time Management

asctime, _wasctime

ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64

gmtime, _gmtime32, _gmtime64

localtime, _localtime32, _localtime64

mktime, _mktime32, _mktime64

time, _time32, _time64

_tzset