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

258
Vistas
How to extract date and time from ISO into local date and time

I have a date and time in ISO

"time": "2021-10-28T17:30:00.000Z"

Below is what I am doing right now to extract the date and time:

var dateExtract = time.substring(0, 10);
var timeExtract = time.match(/\d\d:\d\d/);

But it is giving me the exact date and time written in ISO.

What I want is to extract the date and time in local date and time. I don't know how to do this.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Just create a date object and use toLocaleString or toLocaleDateString or toLocaleTimeString

const date = new Date("2021-10-28T17:30:00.000Z")
console.log(date.toLocaleString())
console.log(date.toLocaleDateString().replaceAll("/","-"))
console.log(date.toLocaleTimeString())

about 4 years ago · Juan Pablo Isaza Denunciar

0

Use the Date instance.

let obj = {"time": "2021-10-28T17:30:00.000Z"}
const dateTime = new Date(obj.time);
const date  = dateTime.toLocaleDateString().replace(/\//g, '-');
// '28-10-2021'
const time = dateTime.toLocaleTimeString()
// '18:30:00' since I am in (+1)

Also find a pool of answers in this similar Question

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are getting dates in a wrong method. when you are reading the date it should be converted to your locale, so that you will get exact date from UTC date

You can use JS Date() function or moment library

let d = new Date("2021-10-28T17:30:00.000Z")

d.toDateString()

d.toLocaleDateString()

check Date functions to get date, month, year, time , seconds or timestamp

refer How to format a JavaScript date

https://www.w3schools.com/js/js_dates.asp

https://www.w3schools.com/js/js_date_formats.asp

Or you can use the external moment library https://momentjs.com/

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