1

After studying I've learned JSON has no standard date literal, which surprised me. I've checked my code and database and it looks like the problem I have is the JSON portion and getting that to appear as MM/DD/YYYY in the datepicker field.

The start value of data.BoardStart is: "/Date(1454519004200)/"

So I'm parsing it using: var BoardStart = new Date(parseInt(data.BoardStart.replace("/Date(", "").replace(")/", ""), 10));

This outputs it to a something like wed feb 03 2016 10:03:24 gmt-0700 (mountain standard time)

This results in an error: BoardStart.format("MM-DD-YYYY");

Any suggestions would be appreciated

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Dreamcasting
  • 454
  • 2
  • 5
  • 21

1 Answers1

1

Your error is because there is no format method on a Date object. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

You have to write your own formatting code or use a library like http://momentjs.com/

var jsonDate = "/Date(1454519004200)/"

var BoardStart = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));

console.log(moment(BoardStart).format('MM-DD-YYYY'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script>
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217