Javascript: Get days & starting day in month

Each month in calendar will have max 28, 29, 30 and 31 days.

We can get using native JS date.

let days = new Date(2022, 8, 0).getDate();
console.log(days);
> 31 // days in August

First day in each month can start from any day.

let st…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Mahesh

Each month in calendar will have max 28, 29, 30 and 31 days.

We can get using native JS date.


let days = new Date(2022, 8, 0).getDate();
console.log(days);
> 31 // days in August

First day in each month can start from any day.

let startingDay = new Date(2022, 8).getDay();
console.log(startingDay);
> 4 // represents Thursday

For more date utils, you can refer: DateUtils

Also, follow for updates: https://twitter.com/urstrulyvishwak


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Mahesh


Print Share Comment Cite Upload Translate Updates
APA

Mahesh | Sciencx (2022-09-10T02:31:00+00:00) Javascript: Get days & starting day in month. Retrieved from https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/

MLA
" » Javascript: Get days & starting day in month." Mahesh | Sciencx - Saturday September 10, 2022, https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/
HARVARD
Mahesh | Sciencx Saturday September 10, 2022 » Javascript: Get days & starting day in month., viewed ,<https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/>
VANCOUVER
Mahesh | Sciencx - » Javascript: Get days & starting day in month. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/
CHICAGO
" » Javascript: Get days & starting day in month." Mahesh | Sciencx - Accessed . https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/
IEEE
" » Javascript: Get days & starting day in month." Mahesh | Sciencx [Online]. Available: https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/. [Accessed: ]
rf:citation
» Javascript: Get days & starting day in month | Mahesh | Sciencx | https://www.scien.cx/2022/09/10/javascript-get-days-starting-day-in-month/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.