Reputation: 3986
I'm using primeng, how can i display a date in input with another format (dd/MM/yyyy) :
<label class="col-form-label" >Date</label>
<input type="text" size="30" pInputText [(ngModel)]="object.dateCreation" [readonly]="true" >
object: Object = {
dateCreation: new Date();
}
Below how the date is diplayed :
Upvotes: 0
Views: 1324
Reputation: 1453
You can use Angular DatePipe
For displaying in HTML ::
{{dateCreation | date: 'dd/MM/yyyy'}}
For sending data to backend, Inject its dependency such as
providers :[DatePipe]
constructor(private datePipe:DatePipe) {}
and now, transform the date using the method available :
this.datePipe.transform(this.dateCreation, 'dd/MM/yyyy');
Upvotes: 1
Reputation: 598
you should apply pipe this way:
<input type="text" size="30" pInputText [ngModel]="object.dateCreation | date : 'medium" (ngModelChange)="object.dateCreation = $event" [readonly]="true">
Upvotes: 2