A timestamp represents a point in time. A program can read one from the system clock, store it as an elapsed value, or print it as a date and time. The printed form may include a time zone; the stored value needs an agreed starting point, called an epoch. section 9.4 section 9.5
An integer encoding is simple and efficient, but its details matter:
- The epoch determines where counting begins. A UNIX timestamp counts seconds since its epoch; Windows FILETIME counts 100-nanosecond increments since 1 January 1601 UTC. section 9.4 section 9.6.2
- A fixed-width integer has a finite range, and discrete units can lose subsecond precision. Do not assume two timestamp formats use the same units or epoch. section 9.4
Read and format the current time
In Rust, `chrono::Local::now()` reads the current system time as a value that includes a time zone. Printing that value gives a formatted timestamp. For a specific output format, use `now.timestamp()` for UNIX seconds, `now.to_rfc2822()` for an email-style date, or `now.to_rfc3339()` for an ISO 8601-compatible date. section 9.5 section 9.6.2
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 }
The formatting branches show how the same `now` value becomes epoch seconds or either of two standardized date strings. section 9.6.2
A timestamp is not necessarily a perfect account of elapsed time. System clocks can jump, while CPU-based timing can be misleading when instructions shift during execution or CPUs run at slightly different rates. Across computers, an NTP client compares its timestamp with a server’s and accounts for network delay before adjusting the local clock. section 9.0 section 9.2 section 9.9









