One problem: you're missing a parenthesis. Change:
var year = (d-(Math.round(d / 100)*100);
to
var year = (d-(Math.round(d / 100)*100));
That being said, this is a more straightforward calculation method:
var year = d % 100;
var month = Math.floor(d / 100) % 100;
var day = Math.floor(d / 10000) % 100;
Next, your array initialization is unnecessarily verbose. Instead of:
var arr = new Array();
arr[0] = "foo";
arr[1] = "bar";
just do:
var arr = ["foo", "bar"];
Your day suffix is incorrect. It puts "nd" after 12 and "12nd April" clearly isn't correct. I would just use logic for doing this rather than a lookup array where most elements are "th".
So:
function timestamp(d){
var year = d % 100;
var month = Math.floor(d / 100) % 100;
var day = Math.floor(d / 10000) % 100;
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
if (year>20) {
year = '19' + year;
} else {
year = '20' + year;
}
if (day == 1 || day == 21 || day == 31) {
var suffix = "st";
} else if (day == 2 || day == 22) {
var suffix = "nd";
} else {
var suffix = "th";
}
return (months[month-1] + ' ' + day + suffix + ', ' + year);
}
Lastly there is little value in your "timestamp" being an integer in its present form. A more typical format for tis kind of thing is YYYYMMDD for two reasons:
Numerical ordering matches date ordering; and
It's unambiguous. North Americans put month before day (ie MMDDYY). Everyone else in the world puts day first (ie DDMMYY). No one does YYDDMM.