April 2024

Print The Current Date/Time Timestamp In Rust

note-to-self: there's a version of this in the rust-grimoire now

---
[dependencies]
chrono = "0.4"
---


fn main() {
  let timestamp = chrono::prelude::Local::now();
  println!("{}", timestamp.to_rfc3339_opts(chrono::SecondsFormat::Secs, true));
  println!("{}", timestamp.to_rfc3339());
  println!("{}", timestamp.to_rfc2822());
  println!("{}", timestamp.format("%B %Y"));
}

// TODO: Add
Output:
2026-06-20T16:59:13-04:00
2026-06-20T16:59:13.952841-04:00
Sat, 20 Jun 2026 16:59:13 -0400
June 2026
end of line

References