let now = new Date();
let arr = now.toDateString().split(' ');
alert(arr[1]+'_'+arr[3]);
let now = new Date();
let shift = -1.0;
let date = now.setMonth(now.getMonth() + shift);
let arr = date.toDateString().split(' ');
alert(arr[1]+'_'+arr[3]);
function formatDate(str) {
const d = new Date(str.replace('_', ' 1, '));
d.setMonth(d.getMonth() - 1);
return d.toLocaleDateString('en-US', {
month: 'short',
year: 'numeric',
}).replace(' ', '_');
}
formatDate('Feb_2021') // "Jan_2021"
formatDate('Jan_2000') // "Dec_1999"