javascript

angularjs moment parse format  #angularjs #reactjs

  • The date filter parse the date based on the object it receive, you should look for a correct Date format for your input date.
  • I think your problem you could be related in how you build your date object
  • new Date(“2-1-2017”) ; // Wed Feb 01 2017
  • If your date variable is a JavaScript Date object you can use angular built-in filter for date as suggested in other answers.
  • If you use moment’s date filter, it has to be a moment date (i.e., complete date with timezone defined) object and you can filter it in the same way that angular does.

I got 1, which I’m expecting 2. how to make moment know my format is actually dd-mm-yyyy not mm-dd-yyy in the view? I don’t want to parse it at my controllers level as it’s complicated.

@ng_real_ninja: angularjs moment parse format #angularjs #reactjs

According to the docs, AngularJs has a built-in filter for date which can be used with the following set:

So that you can use it like:

However if you use moment’s date filter, it has to be a moment date (i.e., complete date with timezone defined) object and you can filter it in the same way that angular does.

variable is a JavaScript Date object you can use angular built-in filter for date as suggested in other answers.

Here a working example:

You should use the angular filter, like:

I think your problem you could be related in how you build your date object

If I do this, 1 refers to the day, which is correct. The date filter parse the date based on the object it receive, you should look for a correct Date format for your input date.

javascript

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.