Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda