0
votes

According to this RFC, sent_time is in ISO 8601 UTC format. Based on that info I should be able to use DateTime::parse_from_rfc3339 to parse sent_time into a DateTime struct, per the docs.

However, using the value of sent_time in the example in the RFC, I get an error. This line of code

let dt = DateTime::parse_from_rfc3339("2019-01-15 18:42:01Z").unwrap_err();

Produces this output if I println! it

`"input contains invalid characters"`

I have tried using both DateTime::parse_from_str and NaiveDateTime::parse_from_str, both of which return the same error: eg this line of code

let dt = NaiveDateTime::parse_from_str("2019-01-15 18:42:01Z", "%Y-%m-%d %H:%M:%S").unwrap_err();

produces if I println! it

"trailing input"

I do not see any documentation about DateTime string formatting which allows for time to formatted like the example above. Perhaps I have missed reading it.

If I have understood the wiki page correct, sent_time example is correctly formatted date time string. Does this seem accurate?

If so, how can I parse it to DateTime struct?

1

1 Answers

1
votes

NaiveDateTime with format %Y-%m-%d %H:%M:%SZ works, notice you need to add the literal Z at the end of format to match your string:

let dt = NaiveDateTime::parse_from_str("2019-01-15 18:42:01Z", "%Y-%m-%d %H:%M:%SZ");
println!("{:?}", dt);
// Ok(2019-01-15T18:42:01)

Playground.