Module serde_with::chrono::datetime_utc_ts_seconds_from_any [−][src]
Expand description
Deserialize a Unix timestamp with optional subsecond precision into a DateTime<Utc>
.
The DateTime<Utc>
can be serialized from an integer, a float, or a string representing a number.
Examples
#[derive(Debug, Deserialize)] struct S { #[serde(with = "serde_with::chrono::datetime_utc_ts_seconds_from_any")] date: DateTime<Utc>, } // Deserializes integers assert!(serde_json::from_str::<S>(r#"{ "date": 1478563200 }"#).is_ok()); // floats assert!(serde_json::from_str::<S>(r#"{ "date": 1478563200.123 }"#).is_ok()); // and strings with numbers, for high-precision values assert!(serde_json::from_str::<S>(r#"{ "date": "1478563200.123" }"#).is_ok());
Functions
deserialize | Deserialize a Unix timestamp with optional subsecond precision into a |