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

别等时光非礼了梦想. 提交于 2019-12-01 03:31:49

问题


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?


回答1:


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)
    }

}



回答2:


Types that implement Error have more user-friendly error messages via Error::description or Display:

Err(e) => println!("{}", e)

This prints:

input is not enough for unique date and time

Presumably this is because you haven't provided a timezone, thus the time is ambiguous.



来源:https://stackoverflow.com/questions/37418464/what-does-parseerrornotenough-from-rust-chrono-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!