Javascript Date getDaySuffix()
// Gen the english suffix for dates Date.prototype.getDaySuffix = function(utc) { var n = this.getUTCDate(); // If not the 11th and date ends at 1 if (n != 11 && (n + '').match(/1$/)) return 'st'; // If not the 12th and date ends at 2 else if (n != 12 && (n + '').match(/2$/)) return 'nd'; // If not the 13th and date ends at 3 else if (n != 13 && (n + '').match(/3$/)) return 'rd'; else/* w ww . ja va 2s . c o m*/ return 'th'; };