【发布时间】:2020-07-30 19:50:51
【问题描述】:
我不知道如何将日期格式更改为此 DD/MM/YYYYY 格式以及如何检索 YYYYY-MM-DD,我将在没有“T00:00:00Z”波浪号的情况下将其添加到其中。
目前我有这种格式显示面:7/15/2020 或 MM/DD/YYYYYY。
有几个线程在谈论这个,但没有一个是我想要的或最近的东西。我在 Angular 10 上使用 Angular Material 模板。
history.component.html
<mat-form-field appearance="fill" >
<mat-label>Enter a date range</mat-label>
<mat-date-range-input [rangePicker]="picker">
<input matStartDate placeholder="Start date">
<input matEndDate placeholder="End date">
</mat-date-range-input>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>
</mat-card-content>
历史化.component.ts 我试过这个没有成功
import { Component, OnInit, Injectable, ViewChild, ChangeDetectorRef } from '@angular/core';
import { RestApiService } from '../../shared/rest-api.service';
import { NotificationsService } from '../../shared/notifications.service';
import { FormControl } from '@angular/forms';
import { Observable, of, Subscription } from 'rxjs';
import { tap, startWith, debounceTime, switchMap, map, filter, distinctUntilChanged } from 'rxjs/operators';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
export const DD_MM_YYYY_Format = {
parse: {
dateInput: 'LL',
},
display: {
dateInput: 'DD/MM/YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
};
@Injectable({
providedIn: 'root'
})
@Component({
selector: 'app-historisation-deploiements',
templateUrl: './historisation-deploiements.component.html',
styleUrls: ['./historisation-deploiements.component.scss'],
providers: [
{provide: MAT_DATE_FORMATS, useValue: DD_MM_YYYY_Format},
]
})
我希望有人能举个例子来做我想做的事。谢谢!
【问题讨论】:
标签: angular datepicker angular-material