A clock needs a starting point as well as a way to count time. That starting point is its epoch. The Unix epoch is 1 January 1970 UTC, so a Unix timestamp expresses elapsed time relative to that date. section 9.2 section 9.4 section 9.6.2
An epoch alone does not specify a complete time format:
- A representation may store whole seconds and a separate fraction of a second. Fixed-width integers make arithmetic straightforward, but limit the range and can introduce rounding. section 9.4
- Other systems choose different starting dates or units. NTP uses 1 January 1900 as its epoch, while Windows FILETIME counts 100-nanosecond increments from 1 January 1601 UTC. section 9.4
A clock starting without a real-time clock
A Raspberry Pi has no battery-backed real-time clock. At startup, its clock begins at epoch time and uses NTP during boot to find the current time. A device that needs accurate timestamps without a network connection can instead add a real-time clock. section 9.1
In a Rust clock application, chrono can print a numeric Unix timestamp or format the same time as an RFC 2822 or RFC 3339 string. For operating systems using libc, time_t holds elapsed seconds since the epoch; setting the system clock also requires a fractional-second value. Do not assume an epoch-based system clock always moves forward: request a monotonic clock when an application requires one. section 9.6.2 section 9.7.2 section 9.10
Listing 9.4 Showing the methods used to format timestamps
48 let now = Clock::get();
49 match std {
50 "timestamp" => println!("{}", now.timestamp()),
51 "rfc2822" => println!("{}", now.to_rfc2822()),
52 "rfc3339" => println!("{}", now.to_rfc3339()),
53 _ => unreachable!(),
54 }
Compare the chrono calls that print seconds since the epoch with those that print formatted dates. section 9.6.2

