Published
Edited
Feb 6, 2019
Testing Big Data
Insert cell
Insert cell
format(before)
Insert cell
format(after)
Insert cell
Insert cell
before = new Date("2019-02-05T11:06:18.642Z")
Insert cell
after = new Date("2019-02-05T11:07:21.482Z")
Insert cell
format = variableFormat(before, after)
Insert cell
function variableFormat(before, after) {
const format = {month: "short", day: "numeric", year: "numeric"};
if (day(before) - day(after) === 0) {
format.hour = "numeric";
if (hour(before) - hour(after) === 0) {
format.minute = "numeric";
if (minute(before) - minute(after) === 0) {
format.second = "numeric";
}
}
}
return date => date.toLocaleString(undefined, format);
}
Insert cell
function day(date) {
date = new Date(date);
date.setHours(0, 0, 0, 0);
return date;
}
Insert cell
function hour(date) {
date = new Date(date);
date.setTime(date - date.getMilliseconds() - date.getSeconds() * 1e3 - date.getMinutes() * 6e4);
return date;
}
Insert cell
function minute(date) {
date = new Date(date);
date.setTime(date - date.getMilliseconds() - date.getSeconds() * 1e3);
return date;
}
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