JS - convert string date to your desire date in Javascript:
var dateStrValue = "Tue, 04/13/2021 - 12:00";
if (dateStrValue != "") {
const monthNames = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"];
var dateStrDateOnlyArray = dateStrValue.split(',');
dateStrDateOnlyArray = dateStrDateOnlyArray[1];
dateStrDateOnlyArray = dateStrDateOnlyArray.split('-');
dateStrDateOnlyArray = dateStrDateOnlyArray[0];
var replaced = dateStrDateOnlyArray.split('/').join('-');
var dateObj = new Date(replaced);
var monthValue = monthNames[dateObj.getMonth()];
var yearValue = dateObj.getFullYear();
$('#prod-date').html(monthValue + ' ' + yearValue);
}
else {
$('#prod-date').html("");
}
Happy coding...
No comments:
Post a Comment