简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM