Home Programming get tomorrows date in format dd-mm-yy in JavaScript

get tomorrows date in format dd-mm-yy in JavaScript

0
get tomorrows date in format dd-mm-yy in JavaScript

[ad_1]

On this tutorial, we’re going to find out about the best way to get the tomorrows date in format dd-mm-yy in JavaScript utilizing the Date object.

Getting the Tomorrows Date in format dd-mm-yy

To get the tomorrows date in foramt dd-mm-yy:

  1. Use the new Date() constructor to entry the present date.

  2. Increment the date by including a 1 day to it utilizing the setDate() and getDate() strategies.

  3. Format the date in dd-mm-yy utilizing the toLocaleDateString() methodology.

Right here is an instance:

const present = new Date();

present.setDate(present.getDate() + 1);

const choices = {day: '2-digit', month: '2-digit', 12 months: '2-digit'};
const tomorrowsDate = present.toLocaleDateString('en-GB', choices);

console.log(tomorrowsDate);

Output:

Within the above instance, at the moment we’ve got a slash ’/’ separator. To vary it to sprint separator ’-’ we will use the replaceAll() methodology in JavaScript.

Right here is an instance:

const tomorrowsDate = present.toLocaleDateString('en-GB', choices);

console.log(tomorrowsDate.replaceAll("https://reactgo.com/", '-')); 

Even when immediately is the final day of a month like August 31. The JavaScript Date object may work out tomorrow’s date is September 1st.

Definitions

  • The setDate() methodology takes the day (from 1 to 31) as an argument and units the worth to a Date object.

  • The getDate() methodology will get the present day of the month (from 1 – 31).

  • The toLocaleDateString() methodology in JavaScript returns a string with a language-sensitive illustration of the date portion of given date within the native timezone.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here