Reputation: 61
my date value is 15.02.2018
i can not convert is date object. when try the error is Invalid Date.
how can i change default date format in angular2+ components
you can check jsfiddle.net/ridvanc/1hk7knwq/1326/
Upvotes: 1
Views: 1775
Reputation: 151
Date constructor accepts Date in MM/DD/YYYY format, whereas you are using DD/MM/YYYY.
Angular provides a DatePipe for formatting dates. You just need to import DatePipe from the common module.
import { DatePipe } from '@angular/common';
Some examples : -
<!--output 'Jun 15, 2015'-->
<p>Today is {{today | date}}</p>
<!--output 'Monday, June 15, 2015'-->
<p>Or if you prefer, {{today | date:'fullDate'}}</p>
<!--output '9:43 AM'-->
<p>The time is {{today | date:'shortTime'}}</p>
<!--output 'Monday, June 15, 2015 at 9:03:01 AM GMT+01:00' -->
<p>The full date/time is {{today | date:'full'}}</p>
Upvotes: 2