Module chrono::serde::ts_seconds
source · Expand description
Ser/de to/from timestamps in seconds
Intended for use with serde
’s with
attribute.
§Example:
use chrono::serde::ts_seconds;
#[derive(Deserialize, Serialize)]
struct S {
#[serde(with = "ts_seconds")]
time: DateTime<Utc>,
}
let time = Utc.with_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap();
let my_s = S { time: time.clone() };
let as_string = serde_json::to_string(&my_s)?;
assert_eq!(as_string, r#"{"time":1431684000}"#);
let my_s: S = serde_json::from_str(&as_string)?;
assert_eq!(my_s.time, time);
Functions§
- Deserialize a
DateTime
from a seconds timestamp - Serialize a UTC datetime into an integer number of seconds since the epoch