Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add days to a Chrono UTC?

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();
like image 821
schmoopy Avatar asked Jun 22 '17 23:06

schmoopy


2 Answers

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.

like image 200
Stargateur Avatar answered Oct 20 '22 05:10

Stargateur


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

like image 40
Yerke Avatar answered Oct 20 '22 05:10

Yerke