Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda