Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I use angular 8. In my html I need to display current date.

(我使用angular8。在我的html中,我需要显示当前日期。)

Here is html code:

(这是html代码:)

   <label class="col-md-4">Creation date </label>
   <input type="date" class="form-control" formControlName="date"/>

How can I display in html above current date?

(如何在当前日期之上的html中显示?)

  ask by Michael translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
338 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

(演示)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...