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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more