Module time::serde::timestamp [−][src]
Expand description
Treat an OffsetDateTime as a Unix timestamp for the purposes of serde.
Use this module in combination with serde’s #[with] attribute.
When deserializing, the offset is assumed to be UTC.
ⓘ
use serde_json::json; #[derive(Serialize, Deserialize)] struct S { #[serde(with = "time::serde::timestamp")] datetime: OffsetDateTime, } let s = S { datetime: date!(2019-01-01).midnight().assume_utc(), }; let v = json!({ "datetime": 1_546_300_800 }); assert_eq!(v, serde_json::to_value(&s)?); assert_eq!(s, serde_json::from_value(v)?);
Modules
| option | Treat an |
Functions
| deserialize | |
| serialize |