微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决将开始月份设置为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 举报,一经查实,本站将立刻删除。