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

263
Visualizações
how to format date pulled from database(inserted as new Date() )

I'm not so sure what's the proper way to insert date into the database, but I'm using new Date().

So I get date format like this when I query from the database:

2021-09-24T12:38:54.656Z

Now I realized that date format is not so user-friendly. So I'm trying to convert it if possible standard readable format like this:

Sept 25 2015, 8:00 PM

I tried using toLocaleString() to my date pulled from db but it won't work probably if I got it correctly pulled date from the db is already a string?

Is there a workaround for this so that I don't need to change how I enter date to my db?

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

0

const date = moment("2021-09-24T12:38:54.656Z").format('MMM D YYYY, h:mm a')
console.log(date)
<script src="https://momentjs.com/downloads/moment.min.js"></script>

use momentjs

You can find format method and apply as you desire

https://momentjs.com/

about 4 years ago · Juan Pablo Isaza Relatório

0

I think it is better to store in DB as UTC 00 value and you are doing it right now.

When you retrieve it, you will be getting a string value something like, 2021-09-24T12:38:54.656Z. On the UI you can easily convert it to date variable in JS using,

const dateVar = new Date("2021-09-24T12:38:54.656Z");
console.log(dateVar.toLocaleString());

If you want more date formatting other than the inbuild solutions like toLocaleString you can use date libraries like moment.js

about 4 years ago · Juan Pablo Isaza Relatório

0

You'd need to create a Date object from the timestamp string like this.

let date = new Date('2021-09-24T12:38:54.656Z');

Then you can use toLocaleString, toLocaleDateString, toDateString, or toString as you see fit.

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