user3842029 user3842029 - 4 months ago 35
AngularJS Question

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

Answer

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