8 Time
Does anybody really know what time it is?
Does anybody really care…?Chicago, 1970
Keeping track of time is a more difficult problem than you might think at first glance. It gets easier if we can decide just how much we really care. By pure coincidence, the release of that song by Chicago roughly corresponds with the start of the Unix Epoch in 1970.
For many applications you don’t need to know the actual day or the hour, but may need to know only how long it has been since a previous event. You may need to know only the approximate elapsed time (update the display about 3 times a second) or something more precise (calculate velocity as ). Life will be easier if you can simply avoid needing to synchronize with real time in the rest of the world. Civil Time, the stuff we run our lives on, is very complicated.
Unix Epoch started 1970-01-01
The simplest standard for real time originated in the Unix operating system as the number of seconds since the beginning of the first day of January, 1970. (‘Real time’ can mean time aligned with astronomical events like days and seasons, or mean things that are happening almost immediately, without any significant delay. ) It has the huge advantage of being an almost monotonically increasing single number that is easy and efficient to handle in your applications. If implemented as an integer, it is monotonically increasing although it can skip values or delay changing for leap seconds. Current time in this form can be obtained from most computer operating systems, or downloaded from the internet using the Network Time Protocol (NTP). Operating systems for networked computers will manage all of this in the background, while micro-controllers will require the programmer to be directly involved in managing the time.
The leap seconds, that allow us to correctly align with astronomical times, mean that time occasionally jumps back or ahead by a second so that the difference between two times may be in error by as much as a second or more. Humans will almost never notice this, but your algorithms may not cope well with elapsed time values that are zero or negative, and can still have significant errors with small positive elapsed times. Avoid using Unix time to calculate time differences unless the time difference is sure to be large.
Synchronizing your own local real time with a standard source always involves a delay. It takes time to transfer a value from the location where it is being constantly updated with the current time, into a message format, and then more time to deliver and decode the message. A full NTP implementation helps estimate these delays, but getting a local real time estimate with an absolute accuracy in milliseconds can be a challenge. It may be adequate in many applications to maintain a lower absolute accuracy, as long as you can measure elapsed times accurately.
Time Zones and Daylight Savings
Unix time is tied to Coordinated Universal Time (UTC), commonly known as Greenwich Mean Time (G