1

I have an angular2 v4 app and I have to show a date in a specific format.

I have this in my component:

currentDate: Date = new Date();

And in my HTML I have this.

<mat-form-field>
  <input matInput [(ngModel)]="currentReport.fromDate" type="text"/>
</mat-form-field>

But In running time, the input look like this:

Sat Nov 17 2018 17:35:26 GMT-0600 (hora estándar central)

How to show the date in format dd/mm/yyyy hh:mm using ngModel?

2 Answers 2

1

You need to format the Date object to a string. One way to do that is with moment .format (https://momentjs.com/docs/#/displaying/)

currentDate: Date = moment(new Date()).format('DD/MM/YYYY HH:mm')
Sign up to request clarification or add additional context in comments.

Comments

0

If this is the only thing you need then initialize it like this in your ts file currentDate: string = new Date().toLocaleString();

if you need other date formats too then use a library like moment

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.