description | title | ms.date | api_name | api_location | api_type | topic_type | f1_keywords | helpviewer_keywords | ms.assetid | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: asctime, _wasctime | asctime, _wasctime | 12/21/2022 |
|
|
|
|
|
| 974f1727-10ff-4ed4-8cac-2eb2d681f576 |
Convert a tm
time structure to a character string. More secure versions of these functions are available; see asctime_s
, _wasctime_s
.
char*asctime( conststructtm*timeptr ); wchar_t*_wasctime( conststructtm*timeptr );
timeptr
Time/date structure.
asctime
returns a pointer to the character string result; _wasctime
returns a pointer to the wide-character string result. There's no error return value.
More secure versions of these functions are available; see asctime_s
, _wasctime_s
.
The asctime
function converts a time stored as a structure to a character string. The timeptr
value is typically obtained from a call to gmtime
or localtime
, which both return a pointer to a tm
structure, defined in TIME.H.
timeptr member | Value |
---|---|
tm_hour | Hours since midnight (0-23) |
tm_isdst | Positive if daylight saving time is in effect; 0 if daylight saving time isn't in effect; negative if status of daylight saving time is unknown. The C run-time library assumes the United States' rules for implementing the calculation of Daylight Saving Time (DST). |
tm_mday | Day of month (1-31) |
tm_min | Minutes after hour (0-59) |
tm_mon | Month (0-11; January = 0) |
tm_sec | Seconds after minute (0-59) |
tm_wday | Day of week (0-6; Sunday = 0) |
tm_yday | Day of year (0-365; January 1 = 0) |
tm_year | Year (current year minus 1900) |
For information about configuring the local time, see the time
, _ftime
, and localtime
functions. For information about defining the time zone environment and global variables, see the _tzset
function.
The string result produced by asctime
contains exactly 26 characters and has the form Wed Jan 2 02:03:55 1980\n\0
. A 24-hour clock is used. All fields have a constant width. The newline character and the null character occupy the last two positions of the string. asctime
uses a single, statically allocated buffer to hold the return string. Each call to this function destroys the result of the previous call.
_wasctime
is a wide-character version of asctime
, and otherwise behaves identically to asctime
.
These functions validate their parameters. If timeptr
is a null pointer, or if it contains out-of-range values, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, the function returns NULL
and sets errno
to EINVAL
.
By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.
TCHAR.H routine | _UNICODE and _MBCS not defined | _MBCS defined | _UNICODE defined |
---|---|---|---|
_tasctime | asctime | asctime | _wasctime |
Routine | Required header |
---|---|
asctime | <time.h> |
_wasctime | <time.h> or <wchar.h> |
This program places the system time in the long integer aclock
, translates it into the structure newtime
, and then converts it to string form for output using the asctime
function.
// crt_asctime.c// compile with: /W3#include<time.h>#include<stdio.h>intmain( void ) { structtm*newTime; time_tszClock; // Get time in secondstime( &szClock ); // Convert time to struct tm formnewTime=localtime( &szClock ); // Print local time as a string.printf_s( "Current date and time: %s", asctime( newTime ) ); // C4996// Note: asctime is deprecated; consider using asctime_s instead }
Current date and time: Sun Feb 3 11:38:58 2002
Time managementctime
, _ctime32
, _ctime64
, _wctime
, _wctime32
, _wctime64
_ftime
, _ftime32
, _ftime64
gmtime
, _gmtime32
, _gmtime64
localtime
, _localtime32
, _localtime64
time
, _time32
, _time64
_tzset
asctime_s
, _wasctime_s