The Flow Of time()
- Time always advances, unless the timezone makes it jump backwards
(e.g. switch from daylight saving time), or unless the system clock
is set abroptly via a 'date' command or similar.
- Thus, we should be careful about how we manage time calculations in code
(e.g. never assume that a future time minus a past time gives a meaningful
result).
- We check the time with:
-
time(NULL)
- returns the number of seconds elapsed
since 1/1/1970 at midnight, in UTC.
- localtime() - translates a given time based on the time zone.
returns the time broken into its parts - year, month, day, hour...
note: the 'month' field is 0-11, not 1-12.
note 2: the 'year' field is the distance from 1900, not the
full year (so year 2005 is represented as 105).
- mktime() - does the inverse of localtime, with the addition of
strange handling of 'out-of-range' values in the various fields (see
the man page...)
Originally written by
guy keren