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

170
Views
Cómo encontrar la diferencia de tiempo en segundos usando moment.js

¿Cómo puedo encontrar la diferencia horaria en segundos entre dos zonas horarias diferentes? Quiero usar el momento para esto: mi hora de inicio es algo así como 2022-09-04T07:29:39Z[UTC] y la hora de finalización será la hora actual en mi interfaz.

mi codigo =

 var now = new Date().getTime(); var then = "2022-03-04T07:29:39Z[UTC]"; var ms = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss")); //NAN var d = moment.duration(ms); var s = d.format("hh:mm:ss"); console.log("Time Difference =",s);

Necesito ayuda en esto, actualmente estoy recibiendo ms como NAN, ¿cómo puedo corregirlo?

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

0

d.format no es una función expuesta por momentjs en lugar de eso, debe escribir como a continuación

 var now = new Date().getTime(); var then = "2022-03-04T07:29:39Z[UTC]"; var ms = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss")); var d = moment.duration(ms); var s = moment(d).format('hh:mm:ss') console.log("Time Difference =",s);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

Este tipo de cálculo se puede hacer fácilmente con Vanilla JavaScript:

 const now = new Date().getTime(), then = new Date("2022-03-04T07:29:39Z"), tsec= Math.round((now-then)/1000), sec=tsec%60, tmin=(tsec-sec)/60, min=tmin%60, th=(tmin-min)/60, h=th%60, d=(th-h)/24; console.log(`Time Difference = ${d}d ${h}h ${min}m ${sec}s`);

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!