JavaScript How to Parse string into Date in angularjs parse string into array,parse string into int,parse string

I have data from the server to display. I receive strings such as this: 2016-05-01. I need to filter the data between two dates in that format. I have a function to parse the date as it is:

$scope.parseDate = function (date) {
  return new Date(Date.parse(date));
} 

In my html I display the date with this:

{{ parseDate(item.startDate) }}`

But in the browser, the result is: "2016-07-12T00:00:00.000Z".

  1. I need the parse the string into the same format as from the server: 2016-05-01.

  2. I need a simple filter function.

I don't want to use moment.js. My backend platform is JavaScript.

Answer:1

Try this in your html :

{{item.startDate | date: 'MMM dd, yyyy'}}
Answer:2

You can use AngularJS filter like below-

$scope.parseDate = function (date) {
    $filter('date')(new Date(Date.parse(date)), 'yyyy-MM-dd');
} 
Answer:3

Something like

function(date) {
   var d = new Date(Date.parse(date));
   return d.getDate() + " " + d.getMonth() + " " + d.getFullYear();
}

Obviously it depends on what date format you desire to output.

Keep in mind that a function is not the best way to format a date in angular because it will be executed continuously and that cause a bad performance problem. You should use a filter like this

app.filter('mydate', function () {
    return function (input) {
        if (input) {

        var d = new Date(input);
        return d.getDate() + " " + d.getMonth() + " " + d.getFullYear();

    }
};
});
Answer:4

In your HTML file try using

{{ parseDate(item.startDate) | date:'yyyy-MM-dd'}}

Answer:5

I'm trying to add the value of the checkbox in the field the is closest to it. But I think I missed something. Please see my code below: $(document).ready(function(){ $("input:checkbox")....

I'm trying to add the value of the checkbox in the field the is closest to it. But I think I missed something. Please see my code below: $(document).ready(function(){ $("input:checkbox")....

  1. pass input checkbox value to controller

I am using a <asp:FileUpload> to upload a PDF file to my web page. But after clicking on browse the window opens, and once I select a file and click on Open i want to get the file name and ...

I am using a <asp:FileUpload> to upload a PDF file to my web page. But after clicking on browse the window opens, and once I select a file and click on Open i want to get the file name and ...

  1. file name from path
  2. file name from path python
  3. file name from path c#
  4. file name from file descriptor
  5. file name from user input java
  6. file name from path java
  7. file name from folder to excel
  8. file name from url
  9. file name from uri android
  10. file name from path bash
  11. file name from path php
  12. file name from url php
  13. file name from path vba
  14. file name from url swift
  15. file name from path ruby
  16. file name from trigger
  17. file name from path shell
  18. filename from file path
  19. file name from url python
  20. file name from file object python

I am trying to test a method using Jest... The method should return Promise.reject() . Here is the code I wrote: test('testing Invalid Response Type', () => { const client = new ...

I am trying to test a method using Jest... The method should return Promise.reject() . Here is the code I wrote: test('testing Invalid Response Type', () => { const client = new ...

What I would like to do is calculate the value of a coordinate in the pascal triangle, I got a table with X and Y axis where I have my pascal triangle aligned at the top and the left, what I'm trying ...

What I would like to do is calculate the value of a coordinate in the pascal triangle, I got a table with X and Y axis where I have my pascal triangle aligned at the top and the left, what I'm trying ...