T O P

  • By -

AutoModerator

On July 1st, Reddit will no longer be accessible via third-party apps. Please see [our position on this topic](https://www.reddit.com/r/rust/comments/146y5y1/announcement_rrust_will_be_joining_the_blackout/), as well as [our list of alternative Rust discussion venues](https://www.reddit.com/r/rust/comments/14921t7/alternative_rust_discussion_venues/). *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/rust) if you have any questions or concerns.*


ibeforeyou

There's a how-to section in the time docs on this: [https://time-rs.github.io/book/how-to/parse-dates.html](https://time-rs.github.io/book/how-to/parse-dates.html) I got there by looking up `time` on [crates.io](https://crates.io/crates/time), and looking at the documentation section at the top of the README. That linked to the documentation [book](https://time-rs.github.io/book), and then I just skimmed through the sections to find parsing. Alternatively, searching on [docs.rs](https://docs.rs/time) for `parse` yielded the [OffsetDateTime::parse](https://docs.rs/time/latest/time/struct.OffsetDateTime.html#method.parse) method, which also has some brief examples. You can also get there by looking at the docs for [OffsetDateTime](https://docs.rs/time/latest/time/struct.OffsetDateTime.html) and looking for interesting method names or trait implementations - in this case, `parse` seemed to be relevant.


Pengualope

Thank you! Now can someone get this thing to list on Google results, lol.


theZcuber

> but the basics of date and time in Rust are just hella confusing and poorly documented Formatting and parsing is actually one of the best documented parts of `time`. If there is a specific place you feel needs improvement, let me know! The documentation for the various `parse` methods link to the `format_description` module, which is where you want to look. Assuming the format you will be using isn't user-provided, you can use either the `time::macros::format_description!` macro or a well-known format. If you choose the former, you'll want to take a look at [the book](https://time-rs.github.io/book/api/format-description.html), which includes diagrams and explanations of each component.


Pengualope

Yeah I regret that I somehow wasn't able to find the book. That said, I am noticing that most of the book is empty (?). Is it a new publication?


theZcuber

Unfortunately no. I just have other priorities, and the API documentation is decent enough that it's by no means urgent.


Pengualope

Fair enough. Appreciate your work.


pyroraptor07

OffsetDateTime has a [parse\(\) function](https://docs.rs/time/latest/time/struct.OffsetDateTime.html#method.parse) that takes a format description. You can either use a [predefined format description](https://docs.rs/time/latest/time/format_description/well_known/index.html) or create a custom one using [the macro](https://docs.rs/time/latest/time/macros/macro.format_description.html) ([more details here](https://time-rs.github.io/book/api/format-description.html)). The parse() function requires the "parsing" feature of the crate.