home ~ projects ~ socials

Get A DateTime From epoch Seconds In Rust

```cargo
[dependencies]
chrono = "0.4.39"
```

use chrono::DateTime;

fn main() {
  let dt = DateTime::from_timestamp(1716700929, 0);
  println!("{}", dt.unwrap());
}
Output:
2024-05-26 05:22:09 UTC

Notes

  • The epoch seconds are also known as a unix timestamp
  • The 0 in from_timestamp is for nanoseconds if you need that precision
-- end of line --