Is there a way to extract Year / Month / Day / Hour / Minute from https://doc.rust-lang.org/std/time/struct.Instant.html

In Instant in std::time - Rust , I see second / milli second / nicro second / nano second.

However, is there a way to extract year / month / day of month, hour, minute ?

There isn't.

You probably want to use chrono, either Local::now() or the Utc version. (and import the Datelike trait)

2 Likes

No, because Instants are not bound to any specified zero point. Given an Instant, there's no way of knowing what calendar datetime it corresponds to. All you can know is the Duration between two Instants.

3 Likes

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.