Skip to content
Discussion options

You must be logged in to vote

Here's a concrete answer to your question:

use jiff::fmt::strtime::BrokenDownTime;

fn main() -> anyhow::Result<()> {
    let input = "2022-10-25 02:53:28 +0100 BST";
    let (tm, _) = BrokenDownTime::parse_prefix("%Y-%m-%d %H:%M:%S %z", input)?;
    let ts = tm.to_timestamp()?;
    println!("{ts}");

    Ok(())
}

And its output:

$ cargo r -q
2022-10-25T01:53:28Z

Or, if you want to parse into a Zoned:

use jiff::fmt::strtime::BrokenDownTime;

fn main() -> anyhow::Result<()> {
    let input = "2022-10-25 02:53:28 +0100 BST";
    let (tm, _) = BrokenDownTime::parse_prefix("%Y-%m-%d %H:%M:%S %z", input)?;
    let zdt = tm.to_zoned()?;
    println!("{zdt}");

    Ok(())
}

And its output:

$ ca…

Replies: 2 comments 1 reply

Comment options

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

Answer selected by BurntSushi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants