How to parse a date with milliseconds?

I have a date in the following format: "2014-03-10 11:20:34.3454" . "2014-03-10 11:20:34.3454" How can I analyze this date?

chrono doc mentions parsing year, month, ..., minutes and seconds. No milliseconds. Also, when I look at rust-datetime again - not milliseconds.

On the other hand, I can create a DateTime like this UTC.ymd(2014, 11, 28).and_hms_milli(7, 8, 9, 10) . Therefore, Rust knows milliseconds ...

+7
rust
source share
1 answer
 extern crate time; fn main() { match time::strptime("2014-03-10 11:20:34.3454", "%Y-%m-%d %H:%M:%S.%f") { Ok(v) => println!("{}", time::strftime("%Y/%m/%d %H:%M:%S.%f", &v).unwrap()), Err(e) => println!("Error: {}", e), }; } 

Output:

 2014/03/10 11:20:34.345400000 

strptime() and strftime() quite useful when using time values. In addition, they usually work in most languages, so learning it once pays well over time.

+5
source share

All Articles