How to assign to a new variable the current time using time::PrimitiveDateTime type? #507
-
I'm using What about Example: pub struct Player {
updated_at: Option<PrimitiveDateTime>
}
impl Player {
pub fn set_updated_at(&mut self) {
let now = Instant::now();
self.updated_at = Some(time::PrimitiveDateTime::from(now));
} But obviously this doesn't work:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
To get the current time, you have to use |
Beta Was this translation helpful? Give feedback.
-
What is the canonical place to read the reasons time shouldn't be stored in UTC, or that |
Beta Was this translation helpful? Give feedback.
To get the current time, you have to use
OffsetDateTime
— specificallyOffsetDateTime::now_utc
orOffsetDateTime::now_local
. This is becauseInstant
is opaque andPrimitiveDateTime
has no time zone or UTC offset — something necessary to indicate a specific point in time.