0

lastupdatedtime:1412674202000

Date is appearing in json object like string. but i want it in date format.

This is my js and html code to display the json object ::

$.ajax({ type : "GET", url : "getPrevComments.html?id="+issueid, dataType : "json",

        success : function(result) {
            if (result.data.length== 0) {
                alert("Please Comment");
                                        } else {
            for ( var i = 0; i < result.data.length; i++) {
                //alert("hhiii"+result.data[i].lastupdatedtime);
                var oo = " <tr>"
                    + "<td >"
                    + "<div  " +
    "style='padding: 0px 10px 10px; background: #CEE0EA; border-radius: 10px; margin-right: 10px; width:166%'>"
                    + "<table>"
                    + "<tr>"
                    + "<td align='left' style='color:#2B6587; font-weight:bold;'>"
                     + result.data[i].shortname
                    + "</td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td>"
                    +  result.data[i].resolution
                    + "</td>"
                    + "</tr>"
                    + "</tab10px 10px 010px 10px 0le>"
                    + "</div>"
                    + "<div " + 
    "style='margin-right: 100px; text-align: left; font-size:8px; color:red; font-weight:bold;'>"
                    **+ result.data[i].lastupdatedtime**
                    + "</div>"
                    + "</td>" + "</tr> ";

            $("#contentid").append(oo);

            }setNiceScrollPosition();
            var objDiv = document.getElementById("chatmsg");
            objDiv.scrollTop = objDiv.scrollHeight;

        }},
JPeroutek
  • 558
  • 1
  • 7
  • 20
  • According to http://www.json.org/ , Date is not a datatype of JSON. If you are trying to just convert a Unix time-stamp to a readable format, perhaps [this question](http://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript) will help? – JPeroutek Jun 05 '15 at 13:15

2 Answers2

1

The value 1412674202000 appears to be a time value for 2014-10-07T09:30:02.000Z. To create an equivalent javascript Date object, convert it to a Number and pass it to the Date constructor:

new Date(Number(result.data[i].lastupdatedtime));

If you want a particular formatted date string, you'll need to build that yourself.

RobG
  • 142,382
  • 31
  • 172
  • 209
  • But i am getting the dat in Tue Jun 09 2015 16:43:34 GMT+0530 (India Standard Time) in this format but i dont want that GMT+0530 to show.. please help me to get this – Vidya Hugar Jun 10 '15 at 09:47
0
var ms=1412674202000;
var date = new Date(ms);
alert(date.toString("dd MM yyyy")); //format date object
  • date.toString("dd MM yyyy") use date format as you required
jignesh
  • 1,639
  • 1
  • 16
  • 18