asctime_r, _wasctime_r
Nach oben zu time.h
Header-Datei
time.h
Kategorie
Uhrzeit- und Datumsroutinen
Prototyp
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);
Beschreibung
Ersetzt asctime und fügt Sicherheitserweiterungen hinzu.
asctime_r konvertiert Datum und Zeit in einen ASCII-String.
wasctime_r konvertiert Datum und Zeit in einen String mit dem Typ wchar_t.
asctime_r und wasctime_r konvertieren in einer Struktur gespeicherte Datums- und Zeitwerte in einen 26 Zeichen langen Einzelbyte- oder Multibyte-String der folgenden Form:
Mon Nov 21 11:31:54 1983\n\0
Alle Felder haben eine konstante Breite. Die ausgegebenen Strings für Wochentag und Monat entsprechen Folgendem:
tm-Parameter Gültiger Bereichswert Ausgabe
tm.mon (Monat) 0-11 0=Jan, 1=Feb usw.
tm.day (Wochentag) 0-6 0=Son, 1=Mon usw.
Bei einer Verletzung von Laufzeiteinschränkungen wird s[0] auf Null gesetzt.
Rückgabewert
asctime_r und wasctime_r geben bei Erfolg 0, ansonsten einen Wert ungleich 0 zurück.
Beispiel
#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;
}
Portabilität
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
asctime_r |
+ |
+ |
+ |
+ |
wasctime_r |
+ |