JavaScript How to parse date field from json using angularJs filter parse date field in excel,parsing field date,json parse

There is no function like format() on the Date prototype in Javascript. But there are these methods:

getDate() // Returns the date
getMonth() // Returns the month
getFullYear() // Returns the year
getHours() // Returns the hour
getMinutes() // Returns the minute
getSeconds() // Returns the second

You can form the string yourself using:

function formatDate(dt) {
    var monthNames = ["January", "February", "March", "April",
        "May", "June", "July", "August", "September",
        "October", "November", "December"];

    var h = dt.getHours(), am;
    if (h > 12) {
        am = 'pm';
        h = h - 12;
    } else {
        am = 'am';
    }

    return monthNames[dt.getMonth()].substring(0, 3) + ' ' +
        dt.getDate() + ', ' + dt.getFullYear() + ' ' +
        h + ':' + dt.getMinutes() + ':' + dt.getSeconds() + ' ' +
        am;
}

console.log(formatDate(new Date(1435837792000+0000)));

If you are finding yourselves in need of more date parsing and formatting, check out the Momentjs library. With moment, you could just do:

moment(new Date(1435837792000+0000)).format("MMM D, YYYY hh:mm:ss A")
Answer:1

Use JS to convert it to Date object & then date function on it..

<html>
<head>
<script>
function jsonDatetoJSDate(){
    var dateFromServer = "/Date(1435837792000+0000)/";
    //Javascript conversion
    var prsdDt = new Date(parseInt(dateFromServer.substr(6)));
    //getting Date Object
    var uDate = new Date(prsdDt);
    alert(uDate);
}
</script>
</head>
<body onload="javascript:jsonDatetoJSDate()">
    Use Date Function on javaScript
</body>
</html>
Answer:2

As you mentioned in comments, if the JSON you are getting is something like

var obj = {
              "PublishDate": "\/Date(1435757849000+0000)\/"
          }

and you have no control in changing the value(since you are enclosing the Date() around slashes), then you would need to

  • escape the slashs around Date.

      obj.PublishDate.replace(/\//g, "");
    
  • and evaluate the remaining expression

      eval(obj.PublishDate.replace(/\//g, ""))
    

to get the actual Date: Wed Jul 08 2015 11:48

Answer:3

You can extract this value from your json.

Assign it to a scope variable in the controller. yourCtrl.js

json = { name: 'stackoverflow',
         date: 1435837792000+0000
       };
$scope.today = new Date(json.date); //This converts the date value from the json to a healthy looking date something like this `2015-07-02T11:49:52.000Z`

today.html

{{ today | date:'medium' }}

This angular filter will display your date in the desired date format. Oct 29, 2010 9:10:23 AM

EDIT:

$scope.today = Date(1435837792000+0000);
$scope.today = new Date($scope.today);

and then pipe it up as using the angular filters as follows

{{ today | date:'MMM d, y hh:mm:ss' }} or {{ today | date:'medium' }} based upon your requirement.

Answer:4

I want to split the following string into 2 arrays. First array from the beginning to '/' and the second from '/' to end. Also, I've tryied with replace to remove the '/' but returns error. var str ...

I want to split the following string into 2 arrays. First array from the beginning to '/' and the second from '/' to end. Also, I've tryied with replace to remove the '/' but returns error. var str ...

  1. string split array
  2. string split array java
  3. string split array c#
  4. string split array javascript
  5. string split array python
  6. string split array php
  7. string split array out of bounds
  8. string split array js
  9. string split array powershell
  10. string split array bash
  11. string split array vb.net
  12. split string to arraylist
  13. string split array vba
  14. string split array sql
  15. string split array int
  16. string split array tsql
  17. string split into arrays
  18. split string array matlab
  19. split string array in java example
  20. split string array with comma c#

I am storing an array of objects in localStorage, retriving it each time, attachibg the new object and again storing. the code works fine, only if there is already an entry in localStorage Following ...

I am storing an array of objects in localStorage, retriving it each time, attachibg the new object and again storing. the code works fine, only if there is already an entry in localStorage Following ...

  1. assign json array to javascript variable
  2. assign json array to variable
  3. assign json array to variable php
  4. assign json array to variable c#
  5. assign json array to variable typescript
  6. assign json array to variable in java
  7. json assign array
  8. assign json to array javascript
  9. assign json to array typescript
  10. how to assign json array to javascript variable
  11. assign json array to variable in javascript
  12. javascript assign json array to variable

So I have an HTML table populated with negative and positive values. I want to query the specific values and then upon hovering over the table values less than 0 I want to highlight the row with a red ...

So I have an HTML table populated with negative and positive values. I want to query the specific values and then upon hovering over the table values less than 0 I want to highlight the row with a red ...

url for LinkedIn advanced search: https://www.linkedin.com/vsearch/p?adv=true&trk=advsrch I am trying to fill fields and hit the submit button on the LinkedIn advanced search page using Selenium (...

url for LinkedIn advanced search: https://www.linkedin.com/vsearch/p?adv=true&trk=advsrch I am trying to fill fields and hit the submit button on the LinkedIn advanced search page using Selenium (...

  1. scrapy use selenium
  2. scrapy with selenium
  3. scrapy with selenium tutorial