Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Rendering returned value from JS function in Razor

I have a page on my site that displays a list of members. I'm using .NET Core MVC and Razor to render my views.

I'm storing the members' registration date as UTC, and would like that date/time converted to the user's local timezone when they view the page.

I'm using javascript to do this:

<script>
    function GetLocalDateTime(utcDate) {
        var localDate = new Date(utcDate);

        console.log(localDate.toString());

        return localDate.toString();
    }
</script>


....


@foreach (var member in Model.Items)
{
    <tr>
        ...
        <td>
            <script>
                GetLocalDateTime('@(member.CreatedDate.ToString("MM/dd/yyyy hh:mm:ss tt UTC"))');
            </script>
        </td>
    </tr>
}

The problem is that the return value from the javascript function doesn't get displayed in my table. But the function is being called, the converted date values are logging in the console.

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want show the date,you need to update the dom rather than just return the local date

modify return localDate.toString(); to document.write( localDate.toString()); enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!