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)
- "input is not enough" for DateTime::parse_from_str but works for Utc.datetime_from_str HOT 2
- Version 0.4.36 has breaking changes with 0.4.35 HOT 2
- Compile error using most recent version of chrono 0.4.36 HOT 2
- Deprecations causing large amount of churn, and result in less elegant code HOT 3
- the trait bound `DateTime<Utc>: OptionFrom/ToWasmAbi` is not satisfied when targeting wasm32 HOT 3
- 0.5: Consider using smaller types for arguments
- Make Weekday::num_days_from public HOT 2
- Add a method to the `Offset` trait to return DST info HOT 5
- 0.5: Add a `LocalOffset` type HOT 4
- Verification of published packages HOT 2
- `gh-pages` branch HOT 3
- Releases has problematic naming of 0.4.8 release which puts it at the top HOT 3
- 0.4.37 semver-incompatibly removes trait bounds on `DateTime` HOT 10
- How do I get the raw underlying bytes of a `NaiveDate` HOT 4
- Parsing from string to DateTime - input is not enough for unique date and time HOT 3
- TimeDelta always returning a PT in seconds HOT 2
- NaiveDate::years_since wrong documentation
- Saturating operations HOT 9
- Datetime Parse Error when converting rfc2822 date to chrono Datetime HOT 2
- Extra slow Utc to Local conversion HOT 6
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.