1// `date` is a `Date` object
2const formatYmd = date => date.toISOString().slice(0, 10);
3
4// Example
5formatYmd(new Date()); // 2020-05-06
1var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
2var today = new Date();
3
4console.log(today.toLocaleDateString("en-US")); // 9/17/2016
5console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
6
7 // For custom format use
8 date.toLocaleDateString("en-US", { day: 'numeric' })+ "-"+ date.toLocaleDateString("en-US", { month: 'short' })+ "-" + date.toLocaleDateString("en-US", { year: 'numeric' }) // 16-Nov-2019
9
1const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
2
3const options = { year: 'numeric', month: 'short', day: 'numeric' };
4
5console.log(event.toLocaleDateString('de-DE', options));
6// expected output: Donnerstag, 20. Dezember 2012
7
8console.log(event.toLocaleDateString('en-US', options));
9// US format
10
11
12// In case you only want the month
13console.log(event.toLocaleDateString(undefined, { month: 'short'}));
14console.log(event.toLocaleDateString(undefined, { month: 'long'}));
1const d = new Date('2010-08-05')
2const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
3const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
4const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
5
6console.log(`${da}-${mo}-${ye}`)