ctime_s, wctime_s

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 ctime_s(char *s, rsize_t maxsize, const time_t *timer);

errno_t wctime_s(wchar_t *s, rsize_t maxsize, const time_t *timer);

Description

Replaces ctime, _wctime adding security enhancements.

Converts date and time to a string.

ctime_s converts the calendar value pointed to by timer (the value returned by the function time) into a 26-character string in the following form, terminating with a newline character and a null character:

Mon Nov 21 11:31:54 1983\n\0

ctime_s is equivalent to asctime_s, wasctime_s as follows:

asctime_s(s, maxsize, localtime_s(timer));

All the fields have constant width.

The global long variable _timezone contains the difference in seconds between GMT and local standard time (in PST, _timezone is 8*60*60). The global variable _daylight is used to indicate to the RTL functions (mktime & localtime) whether they should take daylight saving time into account if a date that would have normally fallen into that category is encountered. It is set to 1 if the daylight savings time conversion should be applied. These variables are set by the tzset function, not by the user program directly.

Return Value

ctime_s returns zero if successful, or nonzero otherwise.

Example

#include <stdio.h>
#include <time.h>
int main(void)
{
  struct tm t;
  unsigned int size = 26;
  char str[80];
  time_t localtime;
  time(&localtime);
  ctime_s(str, size, &localtime);
  printf("%s\n", str);
  return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

ctime_s

+

+

+

+

wctime_s

+

See Also