TheAuzzieJesus TheAuzzieJesus - 1 month ago 4
Javascript Question

Converting dates in YYYY-MM-DD to DD-MONTH in JavaScript

I have the following dates as strings..

2016-10-14
2016-10-15
2016-10-16
2016-10-17
2016-10-18
2016-10-19
2016-10-20


How can I dynamically convert them to the following in JavaScript?

14 Oct
15 Oct
16 Oct
...

Answer

results=[]
string=['2016-10-14', '2016-10-15', '2016-10-16', '2016-10-17', '2016-10-18', '2016-10-19', '2016-10-20']
for(var i=0;i<string.length;++i){
  date=new Date(string[i]);
  list=date.toUTCString().split( " ")
results.push(list[1]+" "+list[2])
}


console.log(results)

Comments