2020 年 4 月 8 日,星期三 00:00:00 GMT+0530(印度标准时间),如何在 angular 中使用日期选择器获取时间
Wed Apr 08 2020 00:00:00 GMT+0530 (India Standard Time), how to get a time using mat date picker in angular
我在表单中使用日期选择器来显示日期,当我显示表单时它工作正常。我需要显示创建的日期和时间,但输出如下:
2020 年 4 月 8 日星期三 00:00:00 GMT+0530(印度标准时间)。如何显示时间?
this.firstFormGroup = this._formBuilder.group({
createAt: [],
})
html
<mat-card-subtitle><b> Created At : </b> {{ firstFormGroup.controls['createAt'].value | date:'short'}}</mat-card-subtitle>
<!-- Date -->
<div class="row">
<b class="dateLabel">Date:</b>
<mat-form-field class="date" (click)="createAt.open()">
<input matInput [matDatepicker]="createAt" autocomplete="off" formControlName="createAt" placeholder="Date"
[value]="createAt" >
<mat-datepicker-toggle matSuffix [for]="createAt"></mat-datepicker-toggle>
<mat-datepicker #createAt></mat-datepicker>
</mat-form-field>
</div>
</div>
使用mat datepicker我们不能显示时间,但是如果我们想显示创建的时间,我们使用下面的代码
使用时刻
moment().format()
它显示当前时间和日期。
我们也可以使用预定义的日期管道
我在表单中使用日期选择器来显示日期,当我显示表单时它工作正常。我需要显示创建的日期和时间,但输出如下: 2020 年 4 月 8 日星期三 00:00:00 GMT+0530(印度标准时间)。如何显示时间?
this.firstFormGroup = this._formBuilder.group({
createAt: [],
})
html
<mat-card-subtitle><b> Created At : </b> {{ firstFormGroup.controls['createAt'].value | date:'short'}}</mat-card-subtitle>
<!-- Date -->
<div class="row">
<b class="dateLabel">Date:</b>
<mat-form-field class="date" (click)="createAt.open()">
<input matInput [matDatepicker]="createAt" autocomplete="off" formControlName="createAt" placeholder="Date"
[value]="createAt" >
<mat-datepicker-toggle matSuffix [for]="createAt"></mat-datepicker-toggle>
<mat-datepicker #createAt></mat-datepicker>
</mat-form-field>
</div>
</div>
使用mat datepicker我们不能显示时间,但是如果我们想显示创建的时间,我们使用下面的代码 使用时刻
moment().format()
它显示当前时间和日期。 我们也可以使用预定义的日期管道