asctime_s, wasctime_s
Go Up to time.h Index
Header File
time.h
Category
Time and Date Routines
Prototype
errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *tmPtr);
errno_t wasctime_s(wchar_t *s, rsize_t maxsize, const struct tm *tmPtr);
Description
Replaces asctime adding security enhancements.
asctime_s converts date and time to ASCII.
wasctime_s converts date and time to a wchar_t string.
asctime_s and wasctime_s convert a time stored as a structure to a 26 (wide) character string in the following form:
Mon Nov 21 11:31:54 1983\n\0
All the fields have a constant width. The output strings day-of-the-week and month correspond to the following:
tm parameterValid value rangeOutput
tm.mon (month)0-110=Jan, 1=Feb, and so on
tm.day (day-of-the-week)0-60=Sun, 1=Mon, and so on
If there is a run-time constraint violation, s[0] is set to null.
Return Value
asctime_s and wasctime_s return zero if successful, or nonzero otherwise.
Example
#include <string.h>
#include <time.h>
#include <stdio.h>
int main(void)
{
struct tm t;
char str[80];
/* Sample loading of tm structure */
t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */
/* Converts structure to null-terminated string */
asctime_s(str, 50, &t);
printf("%s\n", str);
return 0;
}
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
asctime_s |
+ |
+ |
+ |
+ |
wasctime_s |
+ |