Cat*_*155 2 datetime datetime-format rust rust-chrono
我正在尝试将日期时间字符串解析为DateTime对象,但是当我尝试这样做时,我正在获取此ParseError。我不知道发生了什么,有人可以帮我吗?
日期时间字符串: 09-January-2018 12:00:00
码: let date = DateTime::parse_from_str(date.trim(), "%d-%B-%Y %T");
这个:
extern crate chrono;
use chrono::DateTime;
use std::error::Error;
fn main() {
println!("{:?}", DateTime::parse_from_str("09-January-2018 12:00:00", "%d-%B-%Y %T").unwrap_err().description());
}
Run Code Online (Sandbox Code Playgroud)
(https://play.rust-lang.org/?gist=9c0231ea189c589009a46308864dd9bc&version=stable)
提供更多信息:
"input is not enough for unique date and time"
Run Code Online (Sandbox Code Playgroud)
显然,DateTime需要您未在输入中提供的时区信息。使用NaiveDateTime应该起作用:
extern crate chrono;
use chrono::NaiveDateTime;
fn main() {
println!("{:?}", NaiveDateTime::parse_from_str("09-January-2018 12:00:00", "%d-%B-%Y %T"));
}
Run Code Online (Sandbox Code Playgroud)
(https://play.rust-lang.org/?gist=1acbae616c7f084a748e4f9cfaf1ef7f&version=stable)
| 归档时间: |
|
| 查看次数: |
715 次 |
| 最近记录: |