How to construct a datetime with chrono?

use chrono::{self, TimeZone, Utc};

fn main() {
    let a = Utc.ymd(1940, 1, 0);
    let b = Utc.ymd(1940, 3, 0);
    println!("February in 1940 was {:?} days long.", (b - a).num_days());
}

However the code above panics at runtime saying thread 'main' panicked at 'No such local time'.

1 Like

Use a valid day. 0 is not one.

use chrono::{self, TimeZone, Utc};

fn main() {
    let a = Utc.ymd(1940, 1, 1);
    let b = Utc.ymd(1940, 3, 1);
    println!("February in 1940 was {:?} days long.", (b - a).num_days());
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.