I am trying to convert date(integer) to the string. For example from 2019-01-01, my output should be 01 Jan. I wrote the code below.
const dates = ['2019-01-01', '2019-01-02', '2019-01-03', '2019-01-04', '2019-01-05', '2019-01-06', '2019-01-07', '2019-01-08', '2019-01-09'];
let months = [];
let day = [];
let t_stamp = [];
for (let i = 0; i < dates.length; i++) {
let obj = new Date(dates[i]);
months.push(obj.toLocaleString("en-us", {
month: "short"
}));
let con = dates[i].split('-');
day.push(con[2]);
console.log(con);
}
for (let i = 0; i < day.length; i++) {
t_stamp[i] = day[i] + '-' + months[i];
}
This code works almost fine the only issue is, for the first date (2019-01-01) it is giving me output as 01-Dec instead of 01-Jan and for rest of the dates I am getting perfect output ('2019-01-02' = 02-Jan, '2019-01-03' = 03-Jan and so on).
Thank you in advance