1// `date` is a `Date` object
2const formatYmd = date => date.toISOString().slice(0, 10);
3
4// Example
5formatYmd(new Date()); // 2020-05-06
1var date = Date.parse('Sun May 11,2014');
2
3function format(date) {
4 date = new Date(date);
5
6 var day = ('0' + date.getDate()).slice(-2);
7 var month = ('0' + (date.getMonth() + 1)).slice(-2);
8 var year = date.getFullYear();
9
10 return year + '-' + month + '-' + day;
11}
12
13console.log(format(date));