I have a struct that contains a timestamp. For that I am using the chrono library. There are two ways to get the timestamp:
- Parsed from a string via
DateTime::parse_from_str
which results in aDateTime<FixedOffset>
- The current time, received by
UTC::now
which results in aDateTime<UTC>
.
Is there a way to convert DateTime<UTC>
to DateTime<FixedOffset>
?
I believe that you are looking for
DateTime::with_timezone
:I've added a redundant type annotation on
then_utc
to show it is in UTC. This code prints