const zdt = Temporal.ZonedDateTime.from({
year: 2021,
month: 8,
day: 1,
timeZone: "America/New_York",
});
const zdtStr = zdt.toJSON(); // '2021-08-01T00:00:00-04:00[America/New_York]'
const zdt2 = Temporal.ZonedDateTime.from(zdtStr);Temporal.ZonedDateTime.prototype.toJSON() / notebook
Temporal.ZonedDateTime.prototype.toJSON()
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const zdt = Temporal.ZonedDateTime.from({
year: 2021,
month: 8,
day: 1,
timeZone: "America/New_York",
});
const jsonStr = JSON.stringify({ meeting: zdt }); // '{"meeting":"2021-08-01T00:00:00-04:00[America/New_York]"}'
const obj = JSON.parse(jsonStr, (key, value) => {
if (key === "meeting") {
return Temporal.ZonedDateTime.from(value);
}
return value;
});