Published
Edited
Feb 21, 2022
Insert cell
# Date Time Parser
Insert cell
Expected: "2022-02"
Insert cell
Given: "2022-02-14T12:00:00Z"
Insert cell
dateString = "2022-02-14T12:00:00Z"
Insert cell
dateParser = d3.timeParse("%Y-%m-%dT%H:%M:%SZ")
Insert cell
myDateTime = dateParser(dateString)
Insert cell
dateFormat = d3.timeFormat("%Y-%m")
Insert cell
formattedDate = dateFormat(myDateTime)
Insert cell
StringToDate = dateFormat(dateParser(dateString))
Insert cell
dateArrayStr = ["2022-02-14T12:00:00Z", "2022-03-14T12:00:00Z", "2022-04-14T12:00:00Z", "2022-05-14T12:00:00Z"]
Insert cell
DateArray = dateArrayStr.map((d) => dateFormat(dateParser(d)))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more