In your component.ts file, you can get the date as,
(在您的component.ts文件中,您可以获得日期,)
export class AppComponent implements OnInit {
dateVal = new Date();
and display in the component.html, if you want to format you can use DatePipe
as you need
(并显示在component.html中,如果要格式化,可以根据需要使用DatePipe
)
{{dateVal | date: 'M/dd/yyyy'}}
If you need to display in input, you can do
(如果需要在输入中显示,可以执行)
<input type="date" [ngModel] ="dt | date:'yyyy-MM-dd'" (ngModelChange)="dt = $event">
DEMO
(演示)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…