Converting UTC time in model to Local time in view

I have a C# model that includes a list of items, and each item has a DateTime property containing a time that is represented as UTC.

I need to render those times to the UI, which is a cshtml page, and the times should be in local time for the browser.

I am a back-end engineer, very unfamiliar with UI work, but I believe that in order to do this I should pass the C# value through a JavaScript function that does the conversion within the context of the browser. If this is wrong please advise.

I would really like to return the local DateTime value to the cshtml page so that it can be formatted through the same set of standard converters that are used within the project.

My JavaScript function is as follows:

function convertUTCDateTimeToLocalDateTime(date) {
  var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);

  var offset = date.getTimezoneOffset() / 60;
  var hours = date.getHours();

  newDate.setHours(hours - offset);

  return newDate;
}

Within the cshtml file I have a ‘scripts’ section as follows:

@section Scripts
{
    <script src="~/js/datetime-conversion.js" asp-add-nonce="true"></script>
}

Within the body of the cshtml file I would like to be able to do something like this:

@foreach (var thing in things)
{
    DateTime utcTime = thing.DateTimeInUtc;
    DateTime localTime = convertUTCDateTimeToLocalDateTime(@utcTime);

    // Render localTime
}

Please help me out with anything you can. I’ve read as much as I can, but I can’t find the answer to this so I think I’m doing something fundamentally wrong, or my syntax is wrong.