Let's say that I have date as a string, like: 02-12-2011
How can I parse it, and make it in format:
Friday, 02 December, 2011.
Thank you in advance!
Let's say that I have date as a string, like: 02-12-2011
How can I parse it, and make it in format:
Friday, 02 December, 2011.
Thank you in advance!
Something like this should work:
var date = "02-12-2011".split('-');
var month = (date[0] * 1 ) - 1; // * 1 to convert to Number - 1 to subtract to 1 (months are from 0 - 11)
var day = date[1];
var year = data[2];
var d = new Date();
d.setMonth(month);
d.setDate(day);
d.setFullYear(year);
console.log(d.toDateString()); // will output Sat Feb 12 2011
You could also format the date differently by creating your own function that uses the getters getMonth()
, getDate()
, getFullYear()
, getDay()
.
If you'd like a lighter weight solution. Otherwise the link that @diEcho mentions looks good.
Also, the W3School references, while not the best for style, are pretty decent for a general 'get to the facts' reference about the various JavaScript Objects.
Here's a link to the Date object: http://www.w3schools.com/jsref/jsref_obj_date.asp
This blog article on JavaScript date formatting will help on the formatting part.