whatwg_datetime

Function parse_local_datetime

Source
pub fn parse_local_datetime(s: &str) -> Option<NaiveDateTime>
Expand description

Parse a proleptic-Gregorian date consisting of a date, time, with no time-zone information

This follows the rules for parsing a local datetime string per WHATWG HTML Standard § 2.3.5.5 Local dates and times.

§Examples

use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use whatwg_datetime::parse_local_datetime;

// Parse a local datetime string with a date,
// a T delimiter, anda  time with fractional seconds
assert_eq!(
    parse_local_datetime("2011-11-18T14:54:39.929"),
    Some(NaiveDateTime::new(
        NaiveDate::from_ymd_opt(2011, 11, 18).unwrap(),
        NaiveTime::from_hms_milli_opt(14, 54, 39, 929).unwrap(),
    ))
);