美文网首页
antd datepicker周选择器

antd datepicker周选择器

作者: Riya | 来源:发表于2022-03-03 10:48 被阅读0次

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

    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';
    <RangePicker
      picker="week"
      format={[customWeekOfMonthFun, customWeekOfMonthFun]}
      getPopupContainer={(triggerNode) => triggerNode.parentNode}
    />
    

    效果

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

    相关文章

      网友评论

          本文标题:antd datepicker周选择器

          本文链接:https://www.haomeiwen.com/subject/ywasrrtx.html