{"id":5490,"date":"2022-12-20T18:45:16","date_gmt":"2022-12-20T21:45:16","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/localtime-man3p\/"},"modified":"2022-12-20T18:45:16","modified_gmt":"2022-12-20T21:45:16","slug":"localtime-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/localtime-man3p\/","title":{"rendered":"LOCALTIME (man3p)"},"content":{"rendered":"<h1 align=\"center\">LOCALTIME<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">localtime, localtime_r \u2014 convert a time value to a broken-down local time<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <time.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">struct tm *localtime(const time_t *<i>timer<\/i>); <br \/> struct tm *localtime_r(const time_t *restrict <i>timer<\/i>, <br \/> struct tm *restrict <i>result<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For <i>localtime<\/i>(): The functionality described on this reference page is aligned with the ISO\u00a0C standard. Any conflict between the requirements described here and the ISO\u00a0C standard is unintentional. This volume of POSIX.1-2017 defers to the ISO\u00a0C standard.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>localtime<\/i>() function shall convert the time in seconds since the Epoch pointed to by <i>timer<\/i> into a broken-down time, expressed as a local time. The function corrects for the timezone and any seasonal time adjustments. Local timezone information is used as though <i>localtime<\/i>() calls <i>tzset<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The relationship between a time in seconds since the Epoch used as an argument to <i>localtime<\/i>() and the <b>tm<\/b> structure (defined in the <i><time.h><\/i> header) is that the result shall be as specified in the expression given in the definition of seconds since the Epoch (see the Base Definitions volume of POSIX.1-2017, <i>Section 4.16<\/i>, <i>Seconds Since the Epoch<\/i>) corrected for timezone and any seasonal time adjustments, where the names in the structure and in the expression correspond.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The same relationship shall apply for <i>localtime_r<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>localtime<\/i>() function need not be thread-safe.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>asctime<\/i>(), <i>ctime<\/i>(), <i>gmtime<\/i>(), and <i>localtime<\/i>() functions shall return values in one of two static objects: a broken-down time structure and an array of type <b>char<\/b>. Execution of any of the functions may overwrite the information returned in either of these objects by any of the other functions.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>localtime_r<\/i>() function shall convert the time in seconds since the Epoch pointed to by <i>timer<\/i> into a broken-down time stored in the structure to which <i>result<\/i> points. The <i>localtime_r<\/i>() function shall also return a pointer to that same structure.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Unlike <i>localtime<\/i>(), the <i>localtime_r<\/i>() function is not required to set <i>tzname<\/i>. If <i>localtime_r<\/i>() sets <i>tzname<\/i>, it shall also set <i>daylight<\/i> and <i>timezone<\/i>. If <i>localtime_r<\/i>() does not set <i>tzname<\/i>, it shall not set <i>daylight<\/i> and shall not set <i>timezone<\/i>.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, the <i>localtime<\/i>() function shall return a pointer to the broken-down time structure. If an error is detected, <i>localtime<\/i>() shall return a null pointer and set <i>errno<\/i> to indicate the error.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>localtime_r<\/i>() shall return a pointer to the structure pointed to by the argument <i>result<\/i>. If an error is detected, <i>localtime_r<\/i>() shall return a null pointer and set <i>errno<\/i> to indicate the error.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>localtime<\/i>() and <i>localtime_r<\/i>() functions shall fail if: <b><br \/> EOVERFLOW<\/b><\/p>\n<p style=\"margin-left:22%;\">The result cannot be represented.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><b>Getting the Local Date and Time<\/b><\/i> <br \/> The following example uses the <i>time<\/i>() function to calculate the time elapsed, in seconds, since January 1, 1970 0:00 UTC (the Epoch), <i>localtime<\/i>() to convert that value to a broken-down time, and <i>asctime<\/i>() to convert the broken-down time values into a printable string.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <stdio.h> <br \/> #include <time.h><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">int main(void) <br \/> { <br \/> time_t result;<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">result = time(NULL); <br \/> printf(&#8220;%s%ju secs since the Epochn&#8221;, <br \/> asctime(localtime(&#038;result)), <br \/> (uintmax_t)result); <br \/> return(0); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This example writes the current time to <i>stdout<\/i> in a form like this:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Wed Jun 26 10:32:15 1996 <br \/> 835810335 secs since the Epoch<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Getting the Modification Time for a File<\/b> <br \/> The following example prints the last data modification timestamp in the local timezone for a given file.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <stdio.h> <br \/> #include <time.h> <br \/> #include <sys\/stat.h><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">int <br \/> print_file_time(const char *pathname) <br \/> { <br \/> struct stat statbuf; <br \/> struct tm *tm; <br \/> char timestr[BUFSIZ];<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">if(stat(pathname, &#038;statbuf) == -1) <br \/> return -1; <br \/> if((tm = localtime(&#038;statbuf.st_mtime)) == NULL) <br \/> return -1; <br \/> if(strftime(timestr, sizeof(timestr), &#8220;%Y-%m-%d %H:%M:%S&#8221;, tm) == 0) <br \/> return -1; <br \/> printf(&#8220;%s: %s.%09ldn&#8221;, pathname, timestr, statbuf.st_mtim.tv_nsec); <br \/> return 0; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Timing an Event<\/b> <br \/> The following example gets the current time, converts it to a string using <i>localtime<\/i>() and <i>asctime<\/i>(), and prints it to standard output using <i>fputs<\/i>(). It then prints the number of minutes to an event being timed.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <time.h> <br \/> #include <stdio.h> <br \/> &#8230; <br \/> time_t now; <br \/> int minutes_to_event; <br \/> &#8230; <br \/> time(&#038;now); <br \/> printf(&#8220;The time is &#8220;); <br \/> fputs(asctime(localtime(&#038;now)), stdout); <br \/> printf(&#8220;There are still %d minutes to the event.n&#8221;, <br \/> minutes_to_event); <br \/> &#8230;<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>localtime_r<\/i>() function is thread-safe and returns values in a user-supplied buffer instead of possibly using a static data area that may be overwritten by each call.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>asctime<\/i>(), <i>clock<\/i>(), <i>ctime<\/i>(), <i>difftime<\/i>(), <i>getdate<\/i>(), <i>gmtime<\/i>(), <i>mktime<\/i>(), <i>strftime<\/i>(), <i>strptime<\/i>(), <i>time<\/i>(), <i>tzset<\/i>(), <i>utime<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <i>Section 4.16<\/i>, <i>Seconds Since the Epoch<\/i>, <b><time.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  localtime, localtime_r \u2014 convert a time value to a broken-down local time <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1599,1594],"class_list":["post-5490","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-localtime","tag-man3p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5490"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5490\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}