I'm starting with a json string that looks like: ["2016-05-28", "2016-05-29", "2016-05-30", "2016-05-31"]
I'm trying to convert this into Saturday 5/28
Sunday 5/29
.
I looked at these answers and tried to implement the same: Why does Date.parse give incorrect results? and Convert date in string to date object for inserting in database.
But I'm getting the wrong day output. 5/28 comes out as Tuesday, 5/28
when it is a Saturday.
JSFiddle: https://jsfiddle.net/pum40hyx/
Here's my code where I convert the date into my desired string:
function convertToNiceDate(inputDate)
{
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var splitString = inputDate.split("-");
currentDate = new Date(splitString[0], splitString[1], splitString[2]);
var day = currentDate.getDate();
var month = currentDate.getMonth();
//this is the problematic line!
var dayOfWeek = days[currentDate.getDay()];
var dateString = dayOfWeek + ", " + month + "/" + day;
return dateString;
}