Get Tomorrow's Date using JavaScript - Quick Way
Tutorial on how to get tomorrow's date using JavaScript and momentjs library
Lets see how to get tomorrow's date in JavaScript or by using a open-source library like momentjs.
Read about : How to get Yesterday's date in JavaScript
In JavaScript, to get tomorrow's date we have to get the current date using new Date() method and then we have to add one day to it and it will give us the date of the next day.
Using new date() to get tomorrow's date in JavaScript
const today = new Date() const tomorrow = new Date(today) tomorrow.setDate(tomorrow.getDate() + 1) const tomorrowDate = tomorrow.toDateString() console.log(tomorrowDate)
Output:
Fri Jan 07 2022
Code Explanation:
new Date() : Gives current date and time of the day.
getDate() : It extract the date of the month from the string of new Date().
tomorrow.getDate() + 1 : We extract the date (Eg today is 6 ) and then add 1 to it, so we get 7 (next day date).
setDate() : Allow us to change the day of the month. In the code above, we use setDate() to set the value to 7.
toDateString() : It returns the date in proper format in English.
Using JavaScript Library - momentJs
Momentjs is an open-source JavaScript library which remove the need to use the native JavaScript new Date() method.
Using momentJs, we can get the current date in a proper date format by:
moment().format("YYYY-MM-DD")
So to get tomorrow's date using momentJs we have to add 1 as days :
moment().add(1, "days").format("YYYY-MM-DD");
Related Topics:
Related Posts
Code on how to get Yesterday date in JavaScript
This article is about how to get yesterday's date in JavaScript. We will get current date using new Date() and the substract one day from it.
Convert date to long date format using Javascript
Learn how to convert a date to a long date format using Javascript. To convert it to a long format we will be using a toLocaleDateString() method in javascript.
Fix error:0308010C:digital envelope routines::unsupported
Learn to solve the "Error: error:0308010C:digital envelope routines::unsupported" error in Node.js application (Vue, Angular or react) using the solutions in this article.
Press Shift + Enter for new Line in Textarea
Override default textarea behavior on Enter key press without Shift, prevent new lines, and take custom actions like submitting forms instead. Still allow Shift+Enter newlines.
