DEV Community

Kurapati Mahesh
Kurapati Mahesh

Posted on

4 2

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
Enter fullscreen mode Exit fullscreen mode

First day in each month can start from any day.

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

For more date utils, you can refer: DateUtils

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

Top comments (2)

Collapse
 
dhanushnehru profile image
Dhanush N

A point to add is new Date() will take the browser time zone

Collapse
 
urstrulyvishwak profile image
Kurapati Mahesh

True. We can have location based timezone support as well natively.

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay