antd datepicker周选择器

将日期转换为第几周的方法

import moment from 'moment';
moment.locale('zh-cn');
function weekOfMonth(m) {
  return Math.ceil(m.date() / 7);
}
const customWeekOfMonthFun = (weekData) => {
  // console.log(Math.ceil(weekData.day(1).date() / 7), 'weekDate');
  const startDate = moment(weekData).startOf('week');
  // const newDate = moment(weekData);
  let weekMonth = weekOfMonth(startDate);
  let date = startDate.format('YYYY年MM月');
  return `${date}第${weekMonth}周`;
};
export default customWeekOfMonthFun;

周选择器

import customWeekOfMonthFun from './components/customWeekOfMonthFun';
 triggerNode.parentNode}
/>

效果

2022年02月第4周(跨月周跟随上一周)

你可能感兴趣的:(antd datepicker周选择器)