Reputation: 15965
Using the following:
var date = new Date(parseInt(jsonDate.substr(6)));
I get:
Mon Feb 22 1993 00:00:00 GMT+0000 (GMT Standard Time)
How do I format this too
22-02-1993
?
Upvotes: 0
Views: 261
Reputation: 807
var month = date.getMonth();
date.getDate() + "-" + (month >= 10 ? month : '0' + month) + "-" + date.getFullYear();
Read more about Date object in Javascript
Upvotes: 0
Reputation: 1075337
You use the getFullYear
, getMonth
(note that the values start with 0
), and getDate
functions on the Date
instance, then assemble a string. (Those links are to the specification, which can be hard to read; MDC does a bit better.)
Or use a library like DateJS (although it hasn't been maintained in quite some time) or as joidegn mentions, moment.js.
Upvotes: 4