I want to validate if a given string matches the format I need using chrono crate, but I found it's not strict, how can I do it correctly?


use chrono::NaiveDateTime;

fn main() {
    assert!(NaiveDateTime::parse_from_str("23-10-1010:10:10", "%Y-%m-%d %H:%M:%S").is_ok())
}

the string 23-10-1010:10:10 is definitely not matches the format here, but it still works, how can I make it parse with strict match?

thank you.

Use %#Y which is given from[1]

Update: it's unsolvable in chrono v0.4.x.


  1. %#Y doesn't exist in chrono! Rust Playground ↩︎

1 Like

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.