I am building a calendar ponent 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?
I am building a calendar ponent 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?
Share Improve this question edited Aug 31, 2021 at 7:17 JustAG33K 1,5563 gold badges16 silver badges34 bronze badges asked Aug 30, 2021 at 23:57 aydgnaydgn 3571 gold badge2 silver badges9 bronze badges1 Answer
Reset to default 14Day.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