加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – ng-bootstrap datepicker格式

发布时间:2020-12-17 07:20:20 所属栏目:安全 来源:网络整理
导读:我正在使用 ng-bootstrap datepicker但是当我保存表单时,日期会被保存为. date: { day: 01,month: 12,year: 16} 我希望我可以把它保存为更像“2016-11-23T00:39:31.768Z”的东西 这是我的实施: div class="input-group" button class="input-group-btn" (
我正在使用 ng-bootstrap datepicker但是当我保存表单时,日期会被保存为.
date: {
  day: 01,month: 12,year: 16
}

我希望我可以把它保存为更像“2016-11-23T00:39:31.768Z”的东西

这是我的实施:

<div class="input-group">
  <button class="input-group-btn" (click)="d.toggle()" >
    <md-icon svgSrc="assets/images/calendar-plus.svg" style="cursor: pointer;"></md-icon>
  </button>
  <input class="form-control" placeholder="dd-mm-yyyy" name="dp" formControlName="due_date" navigation="arrows" ngbDatepicker #d="ngbDatepicker">
</div>

和form.component:

constructor( private fb: FormBuilder ) {
    this.form = this.fb.group({
      due_date: [''],});
  }
你正在使用ng-bootstrap而不是ng2-bootstrap(不同的组).它背后的代码使用NgbDateStruct,它是一个对象{day,month,year}

在提交时,您需要挂钩并将值更改为其他内容,例如:

onSubmit(): {
    let ngbDate = this.form.controls['due_date'].value;
    let myDate = new Date(ngbDate.year,ngbDate.month-1,ngbDate.day);
    let formValues = this.form.value;
    formValues['due_date'] = myDate;
    <...>
    http.post(url,formValues);
}

https://ng-bootstrap.github.io/#/components/datepicker

NgbDateStruct Interface of the model of the NgbDatepicker and
NgbInputDatepicker directives

Properties

day Type: number The day of month,starting at 1

month Type: number The month,with default calendar we use ISO 8601: 1=Jan
… 12=Dec

year Type: number The year,for example 2016

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读