/ Published in: JavaScript
Example: April 5th, 2011
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var month_names = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), now = new Date(), dayNum = now.getDate(), dayNum_str = dayNum.toString(), dayNum_strlen = dayNum_str.length, dayNum_lastDigit = dayNum_str.substring(dayNum_strlen-1), dayNum_isTeens = null, sup = '', thisMonth = now.getMonth(), thisYear = now.getFullYear(); if (dayNum > 10 && dayNum < 14) { dayNum_isTeens = true; } if (!dayNum_isTeens) { if (dayNum_lastDigit == 1) { sup = 'st'; } else if (dayNum_lastDigit == 2) { sup = 'nd'; } else if (dayNum_lastDigit == 3) { sup = 'rd'; } } else { sup = 'th'; } var date = ''+ month_names[thisMonth] + ' ' + dayNum + '<sup>' + sup + '</sup>, ' + thisYear; document.write(date);