我已经用于mat-datepicker我的 Angular 6 项目。但是在日期选择器中显示当前时区日期。而不是这个,我需要显示当前的 UTC 日期。
这是我的代码
.ts 文件
var nowDate = new Date();
this.startdate = nowDate;
this.enddate = nowDate;
Run Code Online (Sandbox Code Playgroud)
.html 文件
<mat-form-field style="margin-right: 25px;">
<input matInput [matDatepicker]="picker_start" placeholder="Start Date" [(ngModel)]="startdate" [ngModelOptions]="{timezone: 'UTC'}">
<mat-datepicker-toggle matSuffix [for]="picker_start"></mat-datepicker-toggle>
<mat-datepicker #picker_start></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
shh*_*men 14
您可以将 Moment.js 与 Material Datepicker 一起使用,并相应地设置选项,如下所示:
@NgModule({
imports: [MatDatepickerModule, MatMomentDateModule],
providers: [
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
]
})
Run Code Online (Sandbox Code Playgroud)
我在stackblitz上创建了一个示例。您可以在选择日期实现和日期格式设置中找到更多信息。
| 归档时间: |
|
| 查看次数: |
20608 次 |
| 最近记录: |