Input: today Output: SUN Input: tomorrow Output: MON Input: yesterday Output: SAT Input: 01-04-2021 Output: THU
- First, get the current date using the new Date( ) and store it into a variable (date).
- If the input date is tomorrow the using setDate() method increases one date to the Date(), if the input date is yesterday the decrease one date from the Date().
- And if the value is not today then we pass the input date to the Date() object. That’s why if the user inputs today then the Date() will be the default and the default Date() object depicts today’s Date().
- Now by using the date.getDay() method we get the day of the date. It will return a number ranging from 0-6 where 0 represents Sunday and 6 represents Saturday and the remaining days lie in order. Create an array containing the days of the week. By using the index get the preferred day name.
- By using the slice method extract the Beginning three characters.
Example: Create an index.js file and write down the following code.