shammon shammon - 6 months ago 22
AngularJS Question

Angular js: spliting date,month and time using angular filter

I am trying to split up date,month (in words) and time from a timestamp in a

ng-repeat


$scope.notes.forEach(function(notes){
$scope.notes.date = new Date(notes.date);
});


In my view am using angular filter

<div ng-repeat="note in notes">
Date: {{note.date | date:'dd'}}
Month:{{note.date | date:'mm'}}
</div>


This works fine ,but i need two more additional things

1.Month is in words eg: (March)

2.Time parameter eg:2 pm

Is it possible with angular filter?

Note:
Sample timestamp
2016-06-02T16:14:34+0530

Answer

For Month, you can filter it by using the following:

Month:{{note.date | date: 'MMMM'}}

Time can be filtered in two ways depending on how you want to format:

Time:{{note.date | date: 'hh a'}}

OR

Time:{{note.date | date: 'h a'}}

Here's a link to the documentation on date filtering.

Comments