Skip to content

Given an OffsetDateTime, how to find the beginning of the current month and beginning of the next month? #376

Closed Answered by jhpratt
discosultan asked this question in Question
Discussion options

You must be logged in to vote

On the assumption that chrono's DateTime is the same as time's OffsetDateTime:

You can get the year, month, and day by calling OffsetDateTime::to_calendar_date. To get the beginning of the month, call OffsetDateTime::from_calendar_date Date::from_calendar_date with the day set to one. For the next month, you can use Month::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).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@discosultan
Comment options

@jhpratt
Comment options

Answer selected by discosultan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants