Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
¿Cómo obtengo solo la fecha de la cadena "2022-05-25T15: 48: 50.000Z" usando moment.js?

Estoy usando la biblioteca moment.js y, para el ejemplo, digamos que tengo el código:

import moment from "moment-timezone";

const date = "2022-05-25T15:48:50.000Z"

Intenté usar moment(date).format("YYYY-MM-DD") pero, como resultado, obtengo la fecha anterior: 2022-05-24.

Sé que tiene que ver con utc, y mi proyecto tiene en su configuración la línea 'moment.tz.setDefault("Etc/UTC")` que, según tengo entendido, se supone que lo soluciona, pero no lo hace.

Solo lo necesito para tener el resultado final de 2022-05-25 y sé que me estoy perdiendo algo muy pequeño aquí.

¡Agradecería cualquier ayuda!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

prueba esto var newStringDate = yourDate.toISOString().slice(0, 10); o

 var newStringDate = yourDate.toISOString().substring(0, 10);
about 4 years ago · Juan Pablo Isaza Report

0

Su formato es el formato ISO8601, puede consultarlo desde aquí: https://en.wikipedia.org/wiki/ISO_8601

Puede intentar enviar el formato completo a la función.

 const date = "2022-05-25T15:48:50.000Z" var now = moment.utc(date,"YYYY-MM-DD\THH:mm:ss\Z").format("YYYY-MM-DD"); document.getElementById('now').innerHTML = now;
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script> <strong>Should Show: 2022-05-25</strong> <div id="now"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!