Hello I take the current time with chrono::offset::Utc::now()
but it returns this one:
2022-12-01T07:56:54.242352517Z
, I need it like this:
2022-12-01T07:56:54Z
. how can I do this?
CodePudding user response:
You can use to_rfc3339_opts
. It accepts arguments for the format of the seconds and if the Z
should be present.
let time = chrono::offset::Utc::now();
let formatted: String = time.to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
println!("{:?}", time); // 2022-12-01T08:32:20.580242150Z
println!("{}", formatted); // 2022-12-01T08:32:20Z