如何为Chrono UTC添加天数?

时间:2017-06-22 23:33:48

标签: rust rust-chrono

我正在尝试找到向计时器UTC添加天数的首选方法。我想在当前时间增加137天:

let dt = UTC::now();

2 个答案:

答案 0 :(得分:13)

基于doc

extern crate chrono;
extern crate time;

fn main() {
    use chrono::prelude::*;
    use time::Duration;

    let dt = Utc::now() + Duration::days(137);

    println!("{}", dt);
}

Test on playground

答案 1 :(得分:12)

我只想改进@Stargateur的答案。没有必要使用time crate,因为chrono crate中包含Duration个结构:

extern crate chrono;

use chrono::{Duration, Utc};

fn main() {
    let dt = Utc::now() + Duration::days(137);

    println!("{}", dt);
}

Another test on playground