liveBook · Manning

Mktime

As explained in Modern C, Third Edition

mktime is a C standard-library function that normalizes a local broken-down time and converts it to time_t.

mktime normalizes a local broken-down time stored in struct tm, fills its derived fields, and returns the corresponding time_t value. section 8.6

Function form

time_t result = mktime(&tm); passes a struct tm to mktime. The function normalizes hierarchical date members, computes tm_wday and tm_yday, and resolves tm_isdst when it is negative. section 8.6

mktime performs three related operations:

  • Normalizes hierarchical date members to their respective ranges. section 8.6
  • Sets tm_wday and tm_yday to their corresponding weekday and day-of-year values. section 8.6
  • Changes a negative tm_isdst to 1 or 0 according to daylight-saving time on the local platform. section 8.6
  • Returns a time_t on a linear time scale, commonly associated with an epoch near January 1, 1970, though the epoch is not guaranteed. section 8.6

How Modern C, Third Edition covers it

How deep it goes
Explains normalization, derived fields, DST resolution, and time_t conversion, but does not detail implementation internals.
Examples
Uses the mktime declaration and the struct tm fields tm_wday, tm_yday, and tm_isdst as concrete artifacts.
What it assumes
Assumes familiarity with struct tm fields and distinguishes broken-down local time from time_t values.
What you can do after
Apply mktime to normalize a local struct tm and obtain its corresponding time_t representation.
How it connects
Connects struct tm, time_t, daylight-saving time, local time, difftime, and inverse time-conversion functions.

Also explained in

Compare how 2 books explain mktime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.