rustrust-chrono

What does ParseError(NotEnough) from rust-chrono mean?


I'm using rust-chrono and I'm trying to parse a date like this:

extern crate chrono;

use chrono::*;

fn main() {

    let date_str = "2013-02-14 15:41:07";
    let date = DateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S");
    match date {
        Ok(v) => println!("{:?}", v),
        Err(e) => println!("{:?}", e)
    }

}

And this is the output:

ParseError(NotEnough)

What does this mean? Not enough of what? Should I be using some other library?


Solution

  • You should use

    UTC.datetime_from_str(&date_str, "%Y-%m-%d %H:%M:%S");
    

    Like:

    extern crate chrono;
    
    use chrono::*;
    
    fn main() {
    
        let date_str = "2013-02-14 15:41:07";
        let date = UTC.datetime_from_str(&date_str, "%Y-%m-%d %H:%M:%S");
        match date {
            Ok(v) => println!("{:?}", v),
            Err(e) => println!("{:?}", e)
        }
    
    }