-1

How can I convert a serialized date value (1424246400000) to a short date string ("2/23/2015") in mmddyyyy format using javascript?

I've tried using Date() and all I can seem to come up with is a long string...

Date(1424246400000); //"Mon Feb 23 2015 16:56:37 GMT-0800 (Pacific Standard Time)"
tmaurst
  • 552
  • 3
  • 14
  • 34
  • Does this answer your question? http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript?rq=1 – George Feb 24 '15 at 01:02

2 Answers2

1

You should be able to get a simple date string in your current locale format using Date.prototype.toLocaleDateString without any parameters or you can pass "en-US" if you want that locale specifically, eg

var d = new Date(1424246400000);
document.getElementById('date').innerHTML = d.toLocaleDateString('en-US', {
  year: 'numeric',
  month: '2-digit',
  day: '2-digit'
});
<p id="date"></p>
Phil
  • 157,677
  • 23
  • 242
  • 245
0

I realized the issue preventing me from using new Date(serializedString)... serializedString must be an integer, not a string.

tmaurst
  • 552
  • 3
  • 14
  • 34