given my data is:
2011-12-31 01:00:00
what easy and quick script can I use to exctract simply: "DEC 31" ?
Create the following helper functions:
function getMonthName(d) {
var m = ['January','February','March','April','May','June','July',
'August','September','October','November','December'];
return m[d.getMonth()];
}
function getShortMonthName(d) {
return getMonthName(d).substring(0, 3).toUpperCase();
}
And use them like this:
var s = "2011-12-31 01:00:00".split(/-|\s+|:/);
// new Date(year, month, day [, hour, minute, second, millisecond ])
var d = new Date(s[0], s[1] - 1, s[2], s[3], s[4], s[5]);
getShortMonthName(d) + " " + d.getDate();
Output:
"DEC 31"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With