Public
Edited
Mar 8, 2023
Paused
1 star
Insert cell
Insert cell
viewof inputDate = Inputs.date()
Insert cell
sampleDate = inputDate ?? new Date()
Insert cell
Insert cell
function formatDate(date) {
let day = date.getDate();
let month = date.getMonth();
let year = date.getFullYear();
return `${year}-${month + 1}-${day}`;
}
Insert cell
formatDate(sampleDate)
Insert cell
Insert cell
function formatDateUTC(date) {
let day = date.getUTCDate();
let month = date.getUTCMonth();
let year = date.getUTCFullYear();
return `${year}-${month + 1}-${day}`;
}
Insert cell
formatDateUTC(sampleDate)
Insert cell
Insert cell
luxonDate = DateTime.fromJSDate(sampleDate).toUTC() // create a Luxon instance, for use below
Insert cell
luxonDate.toISODate() // yyyy-mm-dd
Insert cell
luxonDate.toLocaleString() // display in whatever format the user's browser is set to
Insert cell
luxonDate.toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)
Insert cell
luxonDate.toFormat("yyyy-MM-dd")
Insert cell
Insert cell
luxon = require("luxon@1/build/amd/luxon.js")
Insert cell
DateTime = luxon.DateTime
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