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

100
Views
moment.js doesn't add hours correctly to the time given

Here is my JS:

var startDateTime = '2021-10-19 20:00:00';
var endDateTime = moment(startDateTime).add(2, 'hours').format('YYYY-MM-DD hh:mm:ss');
  
document.getElementById("startDateTime").innerHTML = startDateTime;
document.getElementById("endDateTime").innerHTML = endDateTime;

I'm expecting endDateTime to be 2021-10-19 22:00:00. But it comes out as 2021-10-19 10:00:00 instead. I'm not sure what I'm doing wrong. Here is the JSFiddle: https://jsfiddle.net/0L3zyqxs/

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

0

To use 24h format in moment.js you need to use HH.

var endDateTime = moment(startDateTime).add(2, 'hours').format('YYYY-MM-DD HH:mm:ss');
about 4 years ago · Juan Pablo Isaza Report

0

please try H as below this is for 24 hours

var endDateTime = moment(startDateTime)
    .add(2, 'hours')
    .format('YYYY-MM-DD HH:mm:ss');
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!