Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Print The Current Date/Time Timestamp In Rust

Code

```cargo
[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"));
}

Results

2024-04-07 12:02:25.633181 -04:00
2024-04-07T12:02:25.633181-04:00
Sun, 7 Apr 2024 12:02:25 -0400
2024-04-07 12:02:25

References