HichamEch
HichamEch

Reputation: 715

How to format date model field in angular 2 form

my model has a field date in mysql format "yyyy-mm-dd hh:ii:ss"

in my form id like to show this field in an input with a custom format : "dd/mm/yyyy"

<input [(ngModel)]="model.date" name="date" view-format="DD/MM/YYYY" model-format="YYYY-MM-DD HH:ii:ss" type="text" class="form-control datePickerUi" >

thanks for help ;)

Upvotes: 0

Views: 2578

Answers (2)

John Baird
John Baird

Reputation: 2676

There is a package called moment that allows you to do all kinds of neat things with dates. http://momentjs.com/docs/

Upvotes: 1

blobbymatt
blobbymatt

Reputation: 317

I have not tested this but it looks like theirs a directive on github to do this. Seen here: https://github.com/eight04/angular-datetime

you would need this code:

<input type="text" datetime="yyyy/MM/dd" ng-model="myDate">

hope it helps!

Upvotes: 0

Related Questions