0

I have a list coming from service. here is the sample json data coming from json

  [
  {
   "Date":"2015-12-09T17:03:56.869-06:00",
   "id":"1",
   "itemCode":"B001"
   "itemName":""
  },
  {
   "Date":"2015-12-02T17:03:56.869-06:00",
   "id":"1",
   "itemCode":"B001"
   "itemName":""
  }...  
  ]

In the view, based on the Date value, I have to display Today(if it is Todays date),then yesterday(if it is yesterdays' Date), and then every day of the week(Tuesday,Monday,Sunday).

Once the list gets to the previous Sunday, should display "Last Week", once the list gets to two Sundays ago, should display, "Two Weeks Ago" and so on up until three weeks. after 3 weeks of lists, it should display "last Month". after the 8th previous Sunday, the header called "Two Months Ago"and so on until 6 months ago. we are getting lists data from last 6 months.

How to get these kind of functionality? is there any filters or built-in methods?

Aurelio
  • 24,702
  • 9
  • 60
  • 63
hanu
  • 397
  • 1
  • 8
  • 20

4 Answers4

0

I'd recommend MomentJS. It is a powerful tool for manipulating dates and has a ton of display features (Time From Now and Calendar are the ones I'd recommend based on your needs).

http://momentjs.com/docs/#/displaying/fromnow/

  • could you give sample code how to use moment.fromNow() – hanu Dec 17 '15 at 18:52
  • Andrew Joslin gives a great example at: http://stackoverflow.com/a/14774933/5691905 If that's not what you're looking for, let me know. – Devin Durtschi Dec 17 '15 at 19:15
  • I use the service route which is called convertToMoment and that basically does: return new moment(datePassedIn); and then call that - convertToMoment(dateNeeded).fromNow(); – Devin Durtschi Dec 17 '15 at 19:21
0

angular date filter doc her :https://docs.angularjs.org/api/ng/filter/date

AlainIb
  • 4,544
  • 4
  • 38
  • 64
0

You can use date filter according to your requirement like {{ date_expression | date : format : timezone}} It will help you for display date in desired format.

Soven K Rout
  • 123
  • 1
  • 9
0

Use Moment js

and in create filter like

.filter('convertDatetoString', function (){
return function(date){
    return moment(date).format("MMM Do");
}})

and in the view using <span ng-bind="date | convertDatetoString"></span>

just refer to http://momentjs.com/ for the formats`

Gidj02
  • 1