liveBook · Manning

Time_t

As explained in Modern C, Third Edition

time_t is an implementation-defined C type used to represent calendar time values.

time_t is a semantic C type for calendar time. Its precision can vary across platforms, so its representation is implementation-dependent rather than a universally fixed numeric format. section 5.2

Comparing calendar times

Obtain timestamps with time(0), then pass two time_t values to difftime(t1, t0) when a time difference suitable for arithmetic is needed. Do not assume that directly subtracting timestamps expresses seconds portably. section 5.2

Table 5.1 Base types according to the four main type classes. Types with a gray background don’t allow for arithmetic; they are promoted before doing arithmetic. Type char is special since it can behave like unsigned or signed, depending on the platform. All types in this table are considered to be distinct types, even if they have the same class and precision.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
ClassSystematic nameOther nameRank
IntegersUnsignedbool_Bool0
unsigned char1
unsigned short2
unsigned intunsigned3
unsigned long4
unsigned long long5
[Un]signedchar1
Signedsigned char1
signed shortshort2
signed intsigned or int3
signed longlong4
signed long longlong long5
Floating pointRealfloat
double
long double
Complexfloat _Complexfloat complex
double _Complexdouble complex
long double _Complexlong double complex

Use the specialized arithmetic-types table to compare time_t with clock_t and other semantic types, including their headers and meanings. section 5.2

How Modern C, Third Edition covers it

How deep it goes
Defines its semantic role and portability limits, but stops short of describing its underlying representation.
Examples
Uses time(0), difftime(t1, t0), and a comparison with clock_t as concrete type examples.
What you can do after
Apply it via time() and difftime() when obtaining timestamps or calculating calendar-time differences.
How it connects
Connects calendar time with difftime, time(), clock_t, processor time, and the epoch.

Also explained in

Compare how 2 books explain time_t →

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.