问题
I am trying to find the preferred way to add days to a Chrono UTC
. I want to add 137 days to the current time:
let dt = UTC::now();
回答1:
Just use Duration and appropriate operator:
use chrono::{Duration, Utc};
fn main() {
let dt = Utc::now() + Duration::days(137);
println!("today date + 137 days {}", dt);
}
Test on playground.
回答2:
I just wanted to improve on @Stargateur answer. There is no need to use time
crate, since chrono
crate has Duration
struct in it:
extern crate chrono;
use chrono::{Duration, Utc};
fn main() {
let dt = Utc::now() + Duration::days(137);
println!("{}", dt);
}
Another test on playground
来源:https://stackoverflow.com/questions/44710877/how-do-i-add-days-to-a-chrono-utc