将开始月份设置为0而不是1 ngb datepicker

问题描述

我正在使用Datepicker控件https://ng-bootstrap.github.io/#/components/datepicker/overview。我正在使用CustomDateParserFormatter将日期解析为其他格式。我的问题是我正在使用dayjs转换日期,其中实习生将日期返回为javascript对象,这意味着月份将从0返回到11,在这种情况下,如果我输入12/12/2012,则datepicker在月份下拉列表中显示为11月。我可以提到日期选择器中的任何地方,月份从0开始而不是从1开始吗?现在我要减去看起来不太干净的月份。

当前的自定义解析器

  parse(value: string | null): NgbDateStruct | any {
    const dateFormat = 'MM/DD/YYYY';
    if (value) {
      const otherthing = dayjs(value).format(dateFormat);
      const tests = dayjs(otherthing);
      const something = {
        day: tests.date(),month: tests.month() + 1,year: tests.year(),};
      return something;
    }
    return null;
  }

  format(date: NgbDateStruct): string {
    if (date) {
      const something = dayjs(new Date(date.year,date.month - 1,date.day));
      return something.format('MM/DD/YYYY');
    }
    return '';
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)