home ~ projects ~ socials

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_string());
  println!("{}", timestamp.to_rfc3339());
  println!("{}", timestamp.to_rfc2822());
  println!("{}", timestamp.format("%Y-%m-%d %H:%M:%S"));
}
Output:
2025-06-07 21:28:26.145204 -04:00
2025-06-07T21:28:26.145204-04:00
Sat, 7 Jun 2025 21:28:26 -0400
2025-06-07 21:28:26
-- end of line --

References