Mr. Newbie
Mr. Newbie

Reputation: 412

Filter for datepicker ui.bootstrap in AngularJs (2014-04-17T07:00:00.000Z )

i have a angular app, and y save date from a datepicker ui.bootstrap, i wanna filter the date and show readble date..

Example: 2014-04-17T07:00:00.000Z to 4/14/2014 or other option

Thanks

Upvotes: 2

Views: 814

Answers (1)

Nidhish Krishnan
Nidhish Krishnan

Reputation: 20741

use Angular filter of date.

{{date  | date:'MM-dd-yyyy HH:MM:ss}}

See the following link - http://docs.angularjs.org/api/ng.filter:date

Example (Working Example)

html

   <div ng-app='myApp' ng-controller="ArrayController">
            <li ng-repeat="arr in records ">
                {{arr.date| date:'MM/dd/yyyy'}}
            </li>
   </div>

script

var app = angular.module('myApp', []);
app.controller('ArrayController', function ($scope) {
    $scope.records = [{
        name: 'sohn',
        phone: '555-1212',
        age: 10,
        date: '2014-11-12T07:00:00.000Z'},
    {
        name: 'Mary',
        phone: '555-9876',
        age: 19,
        date: '2014-05-17T07:00:00.000Z'},
    {
        name: 'Mike',
        phone: '555-4321',
        age: 21,
        date: '2014-04-17T07:00:00.000Z'},
    {
        name: 'Adam',
        phone: '555-5678',
        age: 35,
        date: '2014-09-01T07:00:00.000Z'},
    {
        name: 'Julie',
        phone: '555-8765',
        age: 29,
        date: '2014-10-21T07:00:00.000Z'},
    {
        name: 'Julie',
        phone: '555-8765',
        age: 29,
        date: '2014-11-12T07:00:00.000Z'},
    {
        name: 'arlina',
        phone: '555-8765',
        age: 29,
        date: '2014-07-07T07:00:00.000Z'},
    {
        name: 'Mary',
        phone: '555-8765',
        age: 29,
        date: '2014-06-07T07:00:00.000Z'}
    ];
});

Output

11/12/2014
05/17/2014
04/17/2014
09/01/2014
10/21/2014
11/12/2014
07/07/2014
06/07/2014

Upvotes: 3

Related Questions