user3842029
user3842029

Reputation: 215

Convert date from one format to another - AngularJS

How do I convert date from mm-dd-yyyy to mm/dd/yyyy in AngularJS. Here is the plunker http://plnkr.co/edit/uoeuuHD8GOkPxj5LOlE5?p=preview

$scope.date = '07-28-2016';

{{ data | date:'filter'}} //should return 07/28/2016

Upvotes: 0

Views: 334

Answers (1)

Phil
Phil

Reputation: 165065

First, start with an actual Date instance

$scope.date = new Date('2016-07-28'); // ISO 8601 date formats are less ambiguous

then use the date filter, ie

{{ date | date: 'MM/dd/yyyy' }}

http://plnkr.co/edit/ay2DDwzxQTiBx34bEO5d?p=preview

Upvotes: 2

Related Questions