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

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

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 Denunciar

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 Denunciar

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 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