function getConvertedDate(date, toUTC) { var InPutdate = new Date(date); var LocalTime = InPutdate.getTime(); var LocalOffsetTime = InPutdate.getTimezoneOffset() * 60000; // if true convert to utc else convert from utc to Local if (toUTC) { //Convert to UTC InPutdate = LocalTime + LocalOffsetTime; } else { //UTC to Normal InPutdate = LocalTime - LocalOffsetTime; } var today = new Date(InPutdate); //alert(ConvertedDate) var date = today.getDate(); var month = today.getMonth() + 1; var year = today.getFullYear(); var hours = today.getHours(); var minutes = today.getMinutes(); var ampm = hours >= 12 ? 'PM' : 'AM'; if (date < 10) { date = '0' + date; } if (month < 10) { month = '0' + month; } hours = hours % 12; hours = hours ? hours : 12; minutes = minutes < 10 ? '0' + minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; var finalDate = year + "-" + month + "-" + date + " " + strTime; return finalDate; } alert(getConvertedDate("2022/05/10 08:12:12 PM", true));
+1
+1
+1
+1
+1
+1
+1