asctime_r, _wasctime_r

From RAD Studio
Jump to: navigation, search

Go Up to time.h Index


Header File

time.h

Category

Time and Date Routines

Prototype

errno_t asctime_r(char *s, rsize_t maxsize, const struct tm *tmPtr);
errno_t wasctime_r(wchar_t *s, rsize_t maxsize, const struct tm *tmPtr);

Description

Replaces asctime adding security enhancements.

asctime_r converts date and time to ASCII.

wasctime_r converts date and time to a wchar_t string.

asctime_r and wasctime_r 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_r and wasctime_r 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    = 4;  /* Month */
  t.tm_year   = 120;/* 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_r(&t, str);
  printf("%s\n", str);
  return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

asctime_r

+

+

+

+

wasctime_r

+

See Also