-2

I'm having some trouble to convert an attribute from a JSON which returns a data of type DATE but in this format: 12785950000494 How to pass this value to the next format YYYY-MM-DD I hope you can help me Thanks!!!

  • 2
    poss dupe of http://stackoverflow.com/questions/206384/how-to-format-a-microsoft-json-date – Mark S Apr 27 '16 at 20:33

2 Answers2

0

The format for the date is unix timestamp you can use Date API to transform the date.

Read the documentation about date. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

var timestamp = 12785950000494 
var date = new Date(timestamp)
alert(date);
Jorge Mejia
  • 1,153
  • 1
  • 10
  • 27
0

Here we go:

This method will reconstruct your dateTime string:

var jsonData = new Date();
var formattedDate =  new Date(jsonData);
var strDate = [formattedDate.getFullYear(), formattedDate.getMonth()+1, formattedDate.getDate()].join("-");
alert(strDate);

Hope it helps;)

Husni Salax
  • 1,968
  • 1
  • 19
  • 29