1

The following code gets me the date format as DD.MM.YYYY, which is what I want:

const todayDate = new Date().toLocaleString("ru", {
        day: 'numeric',
        month: '2-digit',
        year: '2-digit'
      })

How do I add days to todayDate (for example, add four days)?

Sabuncu
  • 5,095
  • 5
  • 55
  • 89
4knort
  • 67
  • 1
  • 9

1 Answers1

3

You can try this, first add the day then do the conversion:

var todayDate = new Date()

var newDate = todayDate.setTime( todayDate.getTime() + 4 * 86400000 );// adding 4 days

var dt=new Date (newDate);
console.log(dt.toLocaleString("ru", {
        day: 'numeric',
        month: '2-digit',
        year: '2-digit'
      }));

Another way similar using setDate.

var todayDate = new Date()

var newDate = todayDate.setDate( todayDate.getDate() + 4);// adding 4 days

var dt=new Date (newDate);
console.log(dt.toLocaleString("ru", {
        day: 'numeric',
        month: '2-digit',
        year: '2-digit'
      }));

You should use moment js if you are going to play around with date , it has a lot to offer.

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44