Javascript - Format an integer date (FormatDate)
Convert an integer string (e.g. "/Date(1659369600000)/") to Date
let dateTxt = "/Date(1659369600000)/";
let dateNew = new Date(parseInt(dateTxt.substr(6)));
document.getElementById("demo").innerHTML = date.toDateString() + " " + date.toLocaleTimeString();
result = Thu Sep 22 2022 11:16:07 AM
or
let dateTxt = "/Date(1659369600000)/";
let dateStr = dateStr.match(/\d+/); //"1659369600000"
let dateInt = parseInt(dateStr); //1659369600000
let dateObj = new Date(dateInt); //convert integer to a date
let dateFmt = dateObj.toShortFormat(); //"2-Aug-2022"
Comments
Post a Comment