Comments (7)
You probably want to parse the input as a NaiveDateTime
. That is the closest type to your input, because the timezone information ('UTC') is not part of the input but something you add to it. Code:
NaiveDateTime::parse_from_str(foo, "%Y-%m-%d %H:%M").unwrap().and_utc();
from chrono.
It does since 0.4.32, released two days ago (see #1342) 😄.
from chrono.
convert a
Datetime<FixedOffset>
to aDatetime<Utc>
Can you use the From
trait?
let dtfo: DateTime<FixedOffset> = DateTime::parse_from_str("19700102T23:55:55+00", "%Y%m%dT%H:%M:%S%#z").unwrap();
let dtutc: DateTime<Utc> = DateTime::<Utc>::from(dtfo);
from chrono.
hum ... from the docs for DateTime::parse_from_str
:
Note that this method requires a timezone in the input string.
My input string does not have a timezone, but I know that it's a UTC timestamp.
So should I use a NaiveDateTime? But From<NaiveDateTime>
is not implemented for DateTime<Utc>
.
from chrono.
Indeed, using Datetime::parse_from_str
is not possible with the format I have, I get: "input is not enough for unique date and time"
from chrono.
Yup, this works, thank you!
Maybe the deprecation warning could mention both DateTime::parse_from_str
and NaiveDateTime::parse_from_str
then? It looks like the former is only a replacement if the format has specified a timezone, and the latter needs to be used if the timezone is not part of the format.
from chrono.
Ah! Thank you. I probably did not notice because 0.4.32 failed to build on docs.rs.
from chrono.
Related Issues (20)
- Offer options to configure how to create rfc 3339 string HOT 6
- Split `clock` feature into `clock-now` and `clock-tz` HOT 6
- CI failures in MSRV jobs failing to pick up ahash version
- Operations on NaiveDate are not commutative. HOT 10
- Add `subsec` methods to `Duration` HOT 1
- Time formatting on en_US locale with '%X' not expected HOT 1
- FrameworkNotFound error when building for Apple using maturin HOT 1
- format paniced HOT 11
- panic with_timezone Jan 1, 1601 00:00 UTC HOT 32
- Add methods for float multiplication/division HOT 1
- panic with Local Timezone 2023/11/29 02:00:00 checked_sub_months HOT 2
- rfc HOT 1
- This API seems very complicated HOT 2
- Times before Unix epoch
- Truncating a timestamp close to EPOCH fails HOT 6
- Uhm build fails? HOT 14
- Minimum year changed in 0.4.32 HOT 15
- Breaking change in chrono 0.4.32 (Accepted MAX date changed) HOT 4
- RFC: Bring some of the Rubedo extensions for Chrono into Chrono HOT 23
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chrono.