home ~ projects ~ socials

Print The Current Date/Time Timestamp In Rust

---
[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-04-05 20:19:26.214927 -04:00
2025-04-05T20:19:26.214927-04:00
Sat, 5 Apr 2025 20:19:26 -0400
2025-04-05 20:19:26
-- end of line --

References