.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 19:49:27 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Fri Apr 26 12:38:55 MET DST 1996 by Martin Schulze (joey@linux.de) .\" Modified 2001-11-13, aeb .\" Modified 2001-12-13, joey, aeb .\" Modified 2004-11-16, mtk .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH ctime 3 "18 lutego 2025 r." "Linux man\-pages 6.12" .SH NAZWA asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, localtime_r \- konwertuje daty i czas do postaci czasu rozłożonego lub ASCII .SH BIBLIOTEKA Standardowa biblioteka C (\fIlibc\fP,\ \fI\-lc\fP) .SH SKŁADNIA .nf \fB#include \fP .P \fBchar *asctime(const struct tm *\fP\fItm\fP\fB);\fP \fBchar *asctime_r(const struct tm *restrict \fP\fItm\fP\fB,\fP \fB char \fP\fIbuf\fP\fB[restrict 26]);\fP .P \fBchar *ctime(const time_t *\fP\fItimep\fP\fB);\fP \fBchar *ctime_r(const time_t *restrict \fP\fItimep\fP\fB,\fP \fB char \fP\fIbuf\fP\fB[restrict 26]);\fP .P \fBstruct tm *gmtime(const time_t *\fP\fItimep\fP\fB);\fP \fBstruct tm *gmtime_r(const time_t *restrict \fP\fItimep\fP\fB,\fP \fB struct tm *restrict \fP\fIresult\fP\fB);\fP .P \fBstruct tm *localtime(const time_t *\fP\fItimep\fP\fB);\fP \fBstruct tm *localtime_r(const time_t *restrict \fP\fItimep\fP\fB,\fP \fB struct tm *restrict \fP\fIresult\fP\fB);\fP .P \fBtime_t mktime(struct tm *\fP\fItm\fP\fB);\fP .fi .P .RS -4 Wymagane ustawienia makr biblioteki glibc (patrz \fBfeature_test_macros\fP(7)): .RE .P \fBasctime_r\fP(), \fBctime_r\fP(), \fBgmtime_r\fP(), \fBlocaltime_r\fP(): .nf _POSIX_C_SOURCE || /* glibc w wersji <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE .fi .SH OPIS Funkcje \fBctime\fP(), \fBgmtime\fP() oraz \fBlocaltime\fP() przyjmują argument typu \fItime_t\fP, reprezentujący czas kalendarzowy. Zinterpretowany jako bezwzględna wartość czasu określa liczbę sekund, jakie upłynęły od początku epoki, to jest od 1970\-01\-01 00:00:00 +0000 (UTC). .P Funkcje \fBasctime\fP() oraz \fBmktime\fP() przyjmują jako argument czas rozłożony, który jest reprezentacją podzieloną na rok, miesiąc, dzień itd. .P Czas rozłożony jest przechowywany w strukturze \fItm\fP, opisanej w podręczniku \fBtm\fP(3type). .P Wywołanie \fBctime(\fP\fIt\fP\fB)\fP jest równoważne \fBasctime(localtime(\fP\fIt\fP\fB))\fP. Przekształca czas kalendarzowy \fIt\fP na zakończony znakiem null łańcuch o postaci .P .in +4n .EX "śro, sty 30 21:49:08 1993\[rs]n" .EE .in .P The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". The abbreviations for the months are "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", and "Dec". The return value points to a statically allocated string which might be overwritten by subsequent calls to any of the date and time functions. The function also sets the external variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP as if it called \fBtzset\fP(3). The reentrant version \fBctime_r\fP() does the same, but stores the string in a user\-supplied buffer which should have room for at least 26 bytes. It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. .P Funkcja \fBgmtime\fP() przekształca czas kalendarzowy \fItimep\fP na czas rozłożony, wyrażony w Coordinated Universal Time (UTC). Może zwrócić wartość NULL, jeśli rok nie daje się zapisać jako liczba całkowita. Zwracany jest wskaźnik do statycznej struktury, która to struktura może zostać nadpisana przy kolejnym wywołaniu dowolnej funkcji daty i czasu. Funkcja \fBgmtime_r\fP() robi to samo, ale zapisuje dane do struktury podanej przez użytkownika. .P The \fBlocaltime\fP() function converts the calendar time \fItimep\fP to broken\-down time representation, expressed relative to the user's specified timezone. The function also sets the external variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP as if it called \fBtzset\fP(3). The return value points to a statically allocated struct which might be overwritten by subsequent calls to any of the date and time functions. The \fBlocaltime_r\fP() function does the same, but stores the data in a user\-supplied struct. It need not set \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP. .P Funkcja \fBasctime\fP() przekształca czas rozłożony \fItm\fP na zakończony bajtem null łańcuch tego samego formatu, co \fBctime\fP(). Zwracany jest wskaźnik do statycznego łańcucha, który to łańcuch może zostać nadpisany przy kolejnym wywołaniu dowolnej funkcji daty i czasu. Funkcja \fBasctime_r\fP() robi to samo, ale zapisuje łańcuch w podanym przez użytkownika buforze o długości co najmniej 26 bajtów. .P The \fBmktime\fP() function converts a broken\-down time structure, expressed as local time, to calendar time representation. The function ignores the values supplied by the caller in the \fItm_wday\fP and \fItm_yday\fP fields. The value specified in the \fItm_isdst\fP field informs \fBmktime\fP() whether or not daylight saving time (DST) is in effect for the time supplied in the \fItm\fP structure: a positive value means DST is in effect; zero means that DST is not in effect; and a negative value means that \fBmktime\fP() should (use timezone information and system databases to) attempt to determine whether DST is in effect at the specified time. See \fBtimegm\fP(3) for a UTC equivalent of this function. .P The \fBmktime\fP() function modifies the fields of the \fItm\fP structure as follows: \fItm_wday\fP and \fItm_yday\fP are set to values determined from the contents of the other fields; if structure members are outside their valid interval, they will be normalized (so that, for example, 40 October is changed into 9 November); \fItm_isdst\fP is set (regardless of its initial value) to a positive value or to 0, respectively, to indicate whether DST is or is not in effect at the specified time. The function also sets the external variables \fItzname\fP, \fItimezone\fP, and \fIdaylight\fP as if it called \fBtzset\fP(3). .P Jeśli podany czas rozłożony nie może być reprezentowany jako czas kalendarzowy (sekundy od początku epoki), \fBmktime\fP() zwraca \fI(time_t)\ \-1\fP i nie zmienia pól w podzielonej strukturze czasu. .SH "WARTOŚĆ ZWRACANA" \fBgmtime\fP() oraz \fBlocaltime\fP(), gdy się zakończą pomyślnie, zwracają wskaźnik do \fIstruct\ tm\fP. .P \fBgmtime_r\fP() oraz \fBlocaltime_r\fP(), gdy się zakończą pomyślnie, zwracają adres struktury wskazywanej przez \fIresult\fP. .P \fBasctime\fP() oraz \fBctime\fP(), gdy się zakończą pomyślnie, zwracają wskaźnik do łańcucha znaków .P \fBasctime_r\fP() oraz \fBctime_r\fP(), gdy się zakończą pomyślnie, zwracają wskaźnik do łańcucha znaków, na który wskazuje argument \fIbuf\fP. .P \fBmktime\fP, gdy zakończy się pomyślnie, zwraca czas kalendarzowy (w sekundach od początku epoki [tj. 1970\-01\-01 00:00:00 +0000 \-przyp. tłum.]), wyrażony jako wartość typu \fItime_t\fP .P On error, \fBmktime\fP() returns the value \fI(time_t)\ \-1\fP, and leaves the \fItm\->tm_wday\fP member unmodified. The remaining functions return NULL on error. On error, \fIerrno\fP is set to indicate the error. .SH BŁĘDY .TP \fBEOVERFLOW\fP Wynik jest niereprezentowalny. .SH ATRYBUTY Informacje o pojęciach używanych w tym rozdziale można znaleźć w podręczniku \fBattributes\fP(7). .TS allbox; lb lb lbx l l l. Interfejs Atrybut Wartość T{ .na .nh \fBasctime\fP() T} Bezpieczeństwo wątkowe T{ .na .nh MT\-niebezpieczne race:asctime locale T} T{ .na .nh \fBasctime_r\fP() T} Bezpieczeństwo wątkowe T{ .na .nh MT\-bezpieczne locale T} T{ .na .nh \fBctime\fP() T} Bezpieczeństwo wątkowe T{ .na .nh MT\-niebezpieczne race:tmbuf race:asctime env locale T} T{ .na .nh \fBctime_r\fP(), \fBgmtime_r\fP(), \fBlocaltime_r\fP(), \fBmktime\fP() T} Bezpieczeństwo wątkowe T{ .na .nh MT\-bezpieczne env locale T} T{ .na .nh \fBgmtime\fP(), \fBlocaltime\fP() T} Bezpieczeństwo wątkowe T{ .na .nh MT\-niebezpieczne race:tmbuf env locale T} .TE .SH WERSJE POSIX nie określa parametrów \fBctime_r\fP() jako \fIrestrict\fP; jest to typowe dla glibc. .P Wiele implementacji, włączając glibc, interpretuje 0 w \fItm_mday\fP jako ostatni dzień poprzedniego miesiąca. .P .\" See http://thread.gmane.org/gmane.comp.time.tz/2034/ Według POSIX.1, \fBlocaltime\fP() musi się zachowywać tak, jakby \fBtzset\fP(3) było wywołane, w przypadku zaś \fBlocaltime_r\fP() nie ma takiego wymagania. W przenośnym kodzie \fBtzset\fP(3) powinno być wywołanie przed \fBlocaltime_r\fP(). .SH STANDARDY .TP \fBasctime\fP() .TQ \fBctime\fP() .TQ \fBgmtime\fP() .TQ \fBlocaltime\fP() .TQ \fBmktime\fP() C23, POSIX.1\-2024. .TP \fBgmtime_r\fP() .TQ \fBlocaltime_r\fP() POSIX.1\-2024. .TP \fBasctime_r\fP() .TQ \fBctime_r\fP() Brak. .SH HISTORIA .TP \fBgmtime\fP() .TQ \fBlocaltime\fP() .TQ \fBmktime\fP() C89, POSIX.1\-1988. .TP \fBasctime\fP() .TQ \fBctime\fP() C89, POSIX.1\-1988. Marked obsolescent in C23 and in POSIX.1\-2008 (recommending \fBstrftime\fP(3)). .TP \fBgmtime_r\fP() .TQ \fBlocaltime_r\fP() POSIX.1\-1996. .TP \fBasctime_r\fP() .TQ \fBctime_r\fP() POSIX.1\-1996. Marked obsolescent in POSIX.1\-2008. Removed in POSIX.1\-2024 (recommending \fBstrftime\fP(3)). .SH CAVEATS .SS "Bezpieczeństwo wątkowe" Następujące cztery funkcje \fBacstime\fP(), \fBctime\fP(), \fBgmtime\fP() i \fBlocaltime\fP() zwracają wskaźnik do statycznych danych i w związku z tym nie są przystosowane do wielowątkowości. Wielowątkowe wersje \fBacstime_r\fP(), \fBctime_r\fP(), \fBgmtime_r\fP() i \fBlocaltime_r\fP() są wymienione w SUSv2. .P POSIX.1 says: "The \fBasctime\fP(), \fBctime\fP(), \fBgmtime\fP(), and \fBlocaltime\fP() functions shall return values in one of two static objects: a broken\-down time structure and an array of type \fIchar\fP. Execution of any of the functions that return a pointer to one of these object types may overwrite the information in any object of the same type pointed to by the value returned from any previous call to any of them." This can occur in the glibc implementation. .SS mktime() \fI(time_t) \-1\fP can represent a valid time (one second before the Epoch). To determine whether \fBmktime\fP() failed, one must use the \fItm\->tm_wday\fP field. See the example program in EXAMPLES. .P The handling of a non\-negative \fItm_isdst\fP in \fBmktime\fP() is poorly specified, and passing a value that is incorrect for the time specified yields unspecified results. Since \fBmktime\fP() is one of the few functions that knows when DST is in effect, providing a correct value may be difficult. One workaround for this is to call \fBmktime\fP() twice, once with \fItm_isdst\fP set to zero, and once with \fItm_isdst\fP set to a positive value, and discarding the results from the call that changes it. If neither call changes \fItm_isdst\fP then the time specified probably happens during a fall\-back period where DST begins or ends, and both results are valid but represent two different times. If both calls change it, that could indicate a fall\-forward transition, or some other reason why the time specified does not exist. .P The specification of time zones and daylight saving time are up to regional governments, change often, and may include discontinuities beyond \fImktime\fP's ability to document a result. For example, a change in the timezone definition may cause a clock time to be repeated or skipped without a corresponding DST change. .SH PRZYKŁADY The program below defines a wrapper that allows detecting invalid and ambiguous times, with \fBEINVAL\fP and \fBENOTUNIQ\fP, respectively. .P The following shell session shows sample runs of the program: .P .in +4n .EX $\ \fBTZ=UTC ./a.out 1969 12 31 23 59 59 0\fP; \-1 $ $\ \fBexport TZ=Europe/Madrid\fP; $ $\ \fB./a.out 2147483647 2147483647 00 00 00 00 \-1\fP; a.out: mktime: Value too large for defined data type $ $\ \fB./a.out 2024 08 23 00 17 53 \-1\fP; 1724365073 $\ \fB./a.out 2024 08 23 00 17 53 0\fP; a.out: my_mktime: Invalid argument 1724368673 $\ \fB./a.out 2024 08 23 00 17 53 1\fP; 1724365073 $ $\ \fB./a.out 2024 02 23 00 17 53 \-1\fP; 1708643873 $\ \fB./a.out 2024 02 23 00 17 53 0\fP; 1708643873 $\ \fB./a.out 2024 02 23 00 17 53 1\fP; a.out: my_mktime: Invalid argument 1708640273 $ $\ \fB./a.out 2023 03 26 02 17 53 \-1\fP; a.out: my_mktime: Invalid argument 1679793473 $ $\ \fB./a.out 2023 10 29 02 17 53 \-1\fP; a.out: my_mktime: Name not unique on network 1698542273 $\ \fB./a.out 2023 10 29 02 17 53 0\fP; 1698542273 $\ \fB./a.out 2023 10 29 02 17 53 1\fP; 1698538673 $ $\ \fB./a.out 2023 02 29 12 00 00 \-1\fP; a.out: my_mktime: Invalid argument 1677668400 .EE .SS "Program source: mktime.c" .\" SRC BEGIN (mktime.c) \& .EX #include #include #include #include #include #include #include \& #define is_signed(T) ((T) \-1 < 1) \& time_t my_mktime(struct tm *tp); \& int main(int argc, char *argv[]) { char **p; time_t t; struct tm tm; \& if (argc != 8) { fprintf(stderr, "Usage: %s yyyy mm dd HH MM SS isdst\[rs]n", argv[0]); exit(EXIT_FAILURE); } \& p = &argv[1]; tm.tm_year = atoi(*p++) \- 1900; tm.tm_mon = atoi(*p++) \- 1; tm.tm_mday = atoi(*p++); tm.tm_hour = atoi(*p++); tm.tm_min = atoi(*p++); tm.tm_sec = atoi(*p++); tm.tm_isdst = atoi(*p++); \& errno = 0; tm.tm_wday = \-1; t = my_mktime(&tm); if (tm.tm_wday == \-1) err(EXIT_FAILURE, "mktime"); if (errno == EINVAL || errno == ENOTUNIQ) warn("my_mktime"); \& if (is_signed(time_t)) printf("%jd\[rs]n", (intmax_t) t); else printf("%ju\[rs]n", (uintmax_t) t); \& exit(EXIT_SUCCESS); } \& time_t my_mktime(struct tm *tp) { int e, isdst; time_t t; struct tm tm; unsigned char wday[sizeof(tp\->tm_wday)]; \& e = errno; \& tm = *tp; isdst = tp\->tm_isdst; \& memcpy(wday, &tp\->tm_wday, sizeof(wday)); tp\->tm_wday = \-1; t = mktime(tp); if (tp\->tm_wday == \-1) { memcpy(&tp\->tm_wday, wday, sizeof(wday)); return \-1; } \& if (isdst == \-1) tm.tm_isdst = tp\->tm_isdst; \& if ( tm.tm_sec != tp\->tm_sec || tm.tm_min != tp\->tm_min || tm.tm_hour != tp\->tm_hour || tm.tm_mday != tp\->tm_mday || tm.tm_mon != tp\->tm_mon || tm.tm_year != tp\->tm_year || tm.tm_isdst != tp\->tm_isdst) { errno = EINVAL; return t; } \& if (isdst != \-1) goto out; \& tm = *tp; tm.tm_isdst = !tm.tm_isdst; \& tm.tm_wday = \-1; mktime(&tm); if (tm.tm_wday == \-1) goto out; \& if (tm.tm_isdst != tp\->tm_isdst) { errno = ENOTUNIQ; return t; } out: errno = e; return t; } .EE .\" SRC END .SH "ZOBACZ TAKŻE" \fBdate\fP(1), \fBgettimeofday\fP(2), \fBtime\fP(2), \fButime\fP(2), \fBclock\fP(3), \fBdifftime\fP(3), \fBstrftime\fP(3), \fBstrptime\fP(3), \fBtimegm\fP(3), \fBtzset\fP(3), \fBtime\fP(7) .PP .SH TŁUMACZENIE Autorami polskiego tłumaczenia niniejszej strony podręcznika są: Adam Byrtek , Andrzej Krzysztofowicz , Robert Luberda i Michał Kułach . .PP Niniejsze tłumaczenie jest wolną dokumentacją. Bliższe informacje o warunkach licencji można uzyskać zapoznając się z .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License w wersji 3 .UE lub nowszej. Nie przyjmuje się ŻADNEJ ODPOWIEDZIALNOŚCI. .PP Błędy w tłumaczeniu strony podręcznika prosimy zgłaszać na adres listy dyskusyjnej .MT manpages-pl-list@lists.sourceforge.net .ME .