Function parse_datetime

Source
pub fn parse_datetime<S: AsRef<str> + Clone>(
    s: S,
) -> Result<DateTime<FixedOffset>, ParseDateTimeError>
Expand description

Parses a time string and returns a DateTime representing the absolute time of the string.

§Arguments

  • s - A string slice representing the time.

§Examples

use chrono::{DateTime, Utc, TimeZone};
let time = parse_datetime::parse_datetime("2023-06-03 12:00:01Z");
assert_eq!(time.unwrap(), Utc.with_ymd_and_hms(2023, 06, 03, 12, 00, 01).unwrap());

§Returns

  • Ok(DateTime<FixedOffset>) - If the input string can be parsed as a time
  • Err(ParseDateTimeError) - If the input string cannot be parsed as a relative time

§Errors

This function will return Err(ParseDateTimeError::InvalidInput) if the input string cannot be parsed as a relative time.