MKTIME(3P)
β¨ PROLOG β¨
okay bestie, real talk before we even start π this manual page is part of the POSIX Programmer's Manual. And likeβ¦ the Linux implementation of this interface may differ (so pls go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all π. no cap.
πΈ NAME πΈ
mktime β convert broken-down time into time since the Epoch β°β¨
π SYNOPSIS π
#include <time.h>
time_t mktime(struct tm *timeptr);
π DESCRIPTION π
okay so the functionality described on this reference page? aligned with the ISO C standard, periodt. Any conflict between the requirements described here and the ISO C standard is unintentional β like, we didn't mean it. This volume of POSIX.1β2017 defers to the ISO C standard. fr fr.
The mktime() function shall convert the broken-down time, expressed as local time, in the structure pointed to by timeptr, into a time since the Epoch value with the same encoding as that of the values returned by time(). π
The original values of the tm_wday and tm_yday components of the structure shall be ignored π β like, they're not even invited to the party. And the original values of the other components shall not be restricted to the ranges described in <time.h>. so go wild with them, lowkey.
A positive or 0 value for tm_isdst shall cause mktime() to presume initially that Daylight Savings Time, respectively, is or is not in effect for the specified time. A negative value for tm_isdst shall cause mktime() to attempt to determine whether Daylight Savings Time is in effect for the specified time. she's figuring it out herself π
Local timezone information shall be set as though mktime() called tzset(). π
The relationship between the tm structure (defined in the <time.h> header) and the time in seconds since the Epoch 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, Section 4.16, Seconds Since the Epoch) corrected for timezone and any seasonal time adjustments, where the names other than tm_yday in the structure and in the expression correspond, and the tm_yday value used in the expression is the day of the year from 0 to 365 inclusive, calculated from the other tm structure members specified in <time.h> (excluding tm_wday). math girlies rise π₯
Upon successful completion, the values of the tm_wday and tm_yday components of the structure shall be set appropriately β
, and the other components shall be set to represent the specified time since the Epoch, but with their values forced to the ranges indicated in the <time.h> entry; the final value of tm_mday shall not be set until tm_mon and tm_year are determined. the way that it has to wait its turnβ¦ iconic tbh π
β RETURN VALUE β
The mktime() function shall return the specified time since the Epoch encoded as a value of type time_t. If the time since the Epoch cannot be represented π, the function shall return the value (time_t)-1 and set errno to indicate the error.
π¦ ERRORS π¦
The mktime() function shall fail if:
EOVERFLOWβ The result cannot be represented. π
The following sections are informative.
π EXAMPLES π
What day of the week is July 4, 2001? π let's find out bestie
#include <stdio.h>
#include <time.h>
struct tm time_str;
char daybuf[20];
int main(void)
{
time_str.tm_year = 2001 β 1900;
time_str.tm_mon = 7 β 1;
time_str.tm_mday = 4;
time_str.tm_hour = 0;
time_str.tm_min = 0;
time_str.tm_sec = 1;
time_str.tm_isdst = -1;
if (mktime(&time_str) == -1)
(void)puts("-unknown-");
else {
(void)strftime(daybuf, sizeof(daybuf), "%A", &time_str);
(void)puts(daybuf);
}
return 0;
}
π§ APPLICATION USAGE π§
None. (yes bestie, literally nothing. we love a low-effort section π«Ά)
π RATIONALE π
None. (same energy. nothing to see here πΈ)
πΈ FUTURE DIRECTIONS πΈ
None. (the future isβ¦ empty? slay π )
π SEE ALSO π
asctime(), clock(), ctime(), difftime(), gmtime(), localtime(), strftime(), strptime(), time(), tzset(), utime()
The Base Definitions volume of POSIX.1β2017, Section 4.16, Seconds Since the Epoch, <time.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- 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 .
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 .
ok that's the whole page bestie, every last option and detail accounted for, no gatekeeping π
and a lil sign-off just for you: this iconic piece of documentation came to you courtesy of IEEE/The Open Group, dated 2017, filed under MKTIME(3P) π«Άβ¨ go forth and convert some broken-down time, you absolute main character π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms