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

199
Vistas
Converting a date time to UTC but keeping the same date and time components

New to JavaScript dates and format and also using moment.js but I have the following date/time:

"2021-08-21 00:00:00"

but need to convert it to be this same date/time using moment.js, but in this format:

"2021-08-21T00:00:00.000Z"

To achieve the top date, I am using the following code:

let value = "00:00:00";
let cdt = moment(value, 'HH:mm:ss');
console.log(cdt.format('YYYY-MM-DD HH:mm:ss'))

Unsure what the .000Z are at the end but can someone pls assist with conversion but keeping to same date and time as first date/time

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

0

This is answered by How do I format a date as ISO 8601 in moment.js?

TLDR; you want moment().toISOString();

EDIT: Since you added your code, you'd probably want:

let value = "00:00:00";
let cdt = moment.utc(value, 'HH:mm:ss');
console.log(cdt.toISOString())
<script src="https://momentjs.com/downloads/moment.min.js"></script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

If I understand what you want ... no need for the no longer updated moment.js library

const dateString = "2021-08-21 00:00:00"

const asLocal = dateString.replace(" ", 'T');

const asUTC = asLocal + 'Z';

console.log(new Date(asLocal).toString());
console.log(new Date(asUTC).toUTCString());

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