JSFiddle - React, Tailwind, and code Playground

by jimkennelly

JavaScript

function convertUTCTimeToLocal(utcTimeString) {
  // Create a Date object from the UTC time string.  The 'Z' indicates UTC.
  const utcDate = new Date(utcTimeString);

  // Get the local time string.  This will be in the browser's locale.
  const localTimeString = utcDate.toLocaleString();

  return localTimeString;
}


// Example usage:
const utcTime = "2025-02-17T22:01:28.02Z";
const localTime = convertUTCTimeToLocal(utcTime);

alert("UTC Time:" + utcTime);
alert("Local Time:" + localTime);