liveBook · Manning

Mktime

As explained in Modern C

mktime is a C standard library function that converts a broken-down local calendar time to a time_t value while normalizing its fields.

mktime converts a broken-down local calendar time in struct tm to a time_t value and normalizes the structure’s date fields. section 8.5

Preparing a calendar value

A struct tm uses tm_mon = 0 for January, tm_mday starting at 1, and tm_year as years since 1900. Passing it to mktime normalizes the hierarchical fields, computes tm_wday and tm_yday, and resolves a negative tm_isdst for the local platform. section 8.5

mktime performs three related operations:

  • Normalizes hierarchical date members to their respective ranges. section 8.5
  • Sets tm_wday and tm_yday to their corresponding values. section 8.5
  • Returns the calendar time as arithmetic type time_t, suited to computation on a linear time scale. section 8.5

How Modern C covers it

How deep it goes
Explains field conventions and three normalization steps, but defers implementation details.
Examples
Uses January numbering, Gregorian-year adjustment, weekday and yearday updates, and DST inference as concrete field examples.
What it assumes
Assumes familiarity with struct tm fields and introduces their zero-based, offset, and supplemental conventions.
What you can do after
Apply it via the C library to normalize a local struct tm and obtain a time_t value.
How it connects
Connects struct tm, time_t, difftime, daylight saving time, localtime_s, and gmtime_s.

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. The section links point to the parts of the book it draws on.