// Many options with Intl.DateTimeFormatconst formatter =newIntl.DateTimeFormat('en',{hour12:true,hour:'numeric',minute:'2-digit',second:'2-digit'});
formatter.format(newDate());
const d =newDate.now;const ye =newIntl.DateTimeFormat('en',{year:'numeric'}).format(d);const mo =newIntl.DateTimeFormat('en',{month:'short'}).format(d);const da =newIntl.DateTimeFormat('en',{day:'2-digit'}).format(d);console.log(`${da}-${mo}-${ye}`);
functiondateToYMD(date){var strArray=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];var d = date.getDate();var m = strArray[date.getMonth()];var y = date.getFullYear();return''+(d <=9?'0'+ d : d)+'-'+ m +'-'+ y;}console.log(dateToYMD(newDate(2017,10,5)));// Nov 5
functionformatDate(date){var d =newDate(date),
month =''+(d.getMonth()+1),
day =''+ d.getDate(),
year = d.getFullYear();if(month.length<2)
month ='0'+ month;if(day.length<2)
day ='0'+ day;return[year, month, day].join('-');}console.log(formatDate('Sun May 11,2014'));Run code snippetHide results