GithubHelp home page GithubHelp logo

Comments (7)

pitdicker avatar pitdicker commented on May 28, 2024 1

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.

pitdicker avatar pitdicker commented on May 28, 2024 1

It does since 0.4.32, released two days ago (see #1342) 😄.

from chrono.

jtmoon79 avatar jtmoon79 commented on May 28, 2024

convert a Datetime<FixedOffset> to a Datetime<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.

decathorpe avatar decathorpe commented on May 28, 2024

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.

decathorpe avatar decathorpe commented on May 28, 2024

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.

decathorpe avatar decathorpe commented on May 28, 2024

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.

decathorpe avatar decathorpe commented on May 28, 2024

Ah! Thank you. I probably did not notice because 0.4.32 failed to build on docs.rs.

from chrono.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.