最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect first day of a month with Day.js - Stack Overflow

programmeradmin5浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 14

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

发布评论

评论列表(0)

  1. 暂无评论