JSFiddle - React, Tailwind, and code Playground
by Artem
Babel + JSX
'use strict';
const formatDate = (date, options) => {
const d = new Date(date);
const now = new Date();
const dDate = d.getDate();
const nowDate = d.getDate();
const defaultOptions = {weekday: 'long', month: 'long', day: 'numeric'};
const dateOptions = Object.assign(defaultOptions, options);
const offset = d.getTimezoneOffset();
const newDate = new Date(d.getTime() + offset * 60000);
if (nowDate === dDate) {
return 'Today\'s';
} else if (nowDate + 1 === dDate) {
return 'Tomorrow\'s';
}
let formattedDate = newDate.toLocaleDateString('en-GB', dateOptions);
formattedDate = formattedDate.replace(/(\w+)/, '$1,');
return formattedDate;
};
let d = 1446308460000;
console.log(formatDate(d));