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

179
Visualizações
Weird format Date to `toLocaleString` in javascript

I have an app that is currently running in Production. Suddenly, I have experienced a weird issue that I am not able to figure it out to prevent it. Any suggestion is highly appreciate.

This is the function where the error happened:

date_time: new Date(
                this.selectedDate.getFullYear(),
                this.selectedDate.getMonth(),
                this.selectedDate.getDate(),
                this.selectedHour.value.split(':')[0],
                this.selectedHour.value.split(':')[1],
                0
              ).toLocaleString(),

This date_time will be saved in database. Output Example: 12/9/2021, 2:00:00 PM. Everything is working as expected. However, today there is new record in database with different format: 12/9/2021 2:00:00 p.m. And it messed up my app. Do you know what happen to toLocaleString() ? Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you tagged this angular I assume this code is running client-side and sending the resulting string to the server for insertion into your database.

toLocaleString converts a date to a string formatted for the user's locale.

It is designed to display a human readable date.

If a user with their system set to a different locale (likely because they are from a different country to you) then it will give different results.

If you want a standard date in a format that is easily machine processable (i.e. good for storing in a database) then use toISOString.

You can parse it and convert it to a local string for display later.

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