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>


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