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

118
Views
return date with specified format

I have a date1 and I want to add interval to it and return new date as date2:

const newInterval = 1;
const date1 = '2022-03-02T19:16:51.433Z';
const currentDue = new Date(date1);
const date2 = new Date(new Date().setDate(currentDue.getDate() + newInterval));

console.log(date2);

As you see my date2 format is not same as date1 format and I need to return the date2 with exact format same as the date1!!

So the desired result of date2 would be:

'2022-03-03T19:16:51.433Z';

How can I do this?

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

0

Simply create a new date from the original date and add the interval to that:

const newInterval = 1;
const date1 = '2022-03-02T19:16:51.433Z';
const currentDue = new Date(date1);
const date2 = new Date(currentDue.setDate(currentDue.getDate() + newInterval));
console.log(date2)

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!