It converts UTC ISO Date to local ISO date format. ("2011-10-05T14:48:00.000Z") using basic native JS method.
convertTimeZoneUTCToLocal(date: string | number): string {
const startTime = new Date(date);
return new Date(startTime.toString().split('GMT')[0] + ' UTC').toISOString();}
You can also use moment.js library to convert UTC time to local with below method.
convertTimeZoneUTCToLocal(date: string | number): string {
return moment.utc(date).local().format('YYYY-MM-DDTHH:mm:ss.SSS');
function convertTimeZoneUTCToLocal(date) {
const startTime = new Date(date);
return new Date(startTime.toString().split('GMT')[0] + ' UTC').toISOString();
}
function loadDate(date){
document.getElementById("outputDate").innerHTML = convertTimeZoneUTCToLocal(date);
}
<html>
<head>
<script>
</script>
</head>
<body onload="loadDate('2024-08-23T07:33:51.242Z');">
<div> Input Date : 2024-08-23T07:33:51.242Z </div>
<div> Output Date: <span id="outputDate"></span></div>
</body>
</html>
}
new Date("2012-11-29 17:00:34 UTC")will be in the local time of the client who is using the page