Given an OffsetDateTime, how to find the beginning of the current month and beginning of the next month? #376
-
For example, given an
With Chrono crate, I was able to achieve this using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
On the assumption that chrono's You can get the year, month, and day by calling |
Beta Was this translation helpful? Give feedback.
On the assumption that chrono's
DateTime
is the same as time'sOffsetDateTime
:You can get the year, month, and day by calling
OffsetDateTime::to_calendar_date
. To get the beginning of the month, callOffsetDateTime::from_calendar_date
Date::from_calendar_date
with the day set to one. For the next month, you can useMonth::next
and set the day to one. For that, you'll have to manually adjust the year (should be as easy as checking if the month is December).