Skip to content

How to construct an OffsetDateTime from ymd+hms #442

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

You must be logged in to vote

UtcOffset::from_hms(3, 4, 5) creates an offset from UTC, not a time.

What you're looking for is:

Date::from_calendar_date(2010, Month::January, 2)?
    .with_hms(3, 4, 5)?
    .assume_utc()

Assuming you want UTC to be the offset. If not, you'll want to use PrimitiveDateTime::assume_offset.

If these values are statically known, I suggest you use the macros instead:

datetime!(2010-01-02 03:04:05 UTC)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nicholasbishop
Comment options

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