Get The Current UTC DateTime In Rust
---
[dependencies]
chrono = "0.4.40"
---
use chrono::offset::Utc;
fn main() {
let dt = Utc::now();
println!("{}", dt);
println!("{}", dt.to_rfc2822());
println!("{}", dt.to_rfc3339());
println!("{}", dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, true));
}
Output:
2025-04-24 03:37:47.155293 UTC
Thu, 24 Apr 2025 03:37:47 +0000
2025-04-24T03:37:47.155293+00:00
2025-04-24T03:37:47Z
-- end of line --