5

I am building a calendar component in React without using any library but Day.js.

I need to detect the first weekday of the month in order to leave a gap as shown in the picture. Otherwise the first day of every month has to be Sunday. How can I detect the first weekday of the given date?

calendar

JustAG33K
  • 1,403
  • 3
  • 13
  • 28
aydgn
  • 167
  • 1
  • 8

1 Answers1

8

Day.js has built in function to achieve this

dayjs().startOf("month").day() 

This method returns current month's first week day as number.

0 = Sunday, 6 = Saturday

aydgn
  • 167
  • 1
  • 8