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

151
Views
Add days to Date object and then converting to local string?

How can i add 5 days to the current date, and then convert it to a string representing the local date and time?

const newDate = new Date();

const test = newDate.setDate(newDate.getDate() + 5).toLocaleString();

Just returns the number of milliseconds.. (same if i use toString().

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

0

Without using any libraries, Vanilla JS solution:

const now = new Date()
const inFiveDays = new Date(new Date(now).setDate(now.getDate() + 5))
console.log('now', now.toLocaleString())
console.log('inFiveDays', inFiveDays.toLocaleString())

This even works when your date overflows the current month.

about 4 years ago · Juan Pablo Isaza Report

0

The easiest way is by using a date library like Moment.js or date-fns. I gave an example below using date-fns and addDays

const today = new Date();
const fiveDaysLater = addDays(newDate, 5);
about 4 years ago · Juan Pablo Isaza Report

0

Just use new Date() in front of it.

const newDate = new Date();
const add  =5
const test = newDate.setDate(newDate.getDate() + add)
console.log(new Date(test).toLocaleString());

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!