在Angular 10中,您可以使用Angular的内置日期管道来格式化日期。下面是一个在HTML模板中格式化日期的示例:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent {
currentDate: Date = new Date();
}
当前日期:{{ currentDate | date:'yyyy-MM-dd' }}
在上面的示例中,我们使用了date
管道来格式化日期。yyyy-MM-dd
是日期格式的表达式,可以根据您的需求进行更改。
这就是使用Angular 10在HTML中格式化日期的解决方法。