Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function formatDate(date) {
- var ds = date.toDateString().split(/ /),
- mon = monthDict[date.getMonth()],
- day = date.getDate()+'',
- dayi = parseInt(day),
- year = date.getFullYear(),
- thisyear = (new Date()).getFullYear(),
- th = 'th';
- // anti-'th' - but don't do the 11th, 12th or 13th
- if ((dayi % 10) == 1 && day.substr(0, 1) != '1') {
- th = 'st';
- } else if ((dayi % 10) == 2 && day.substr(0, 1) != '1') {
- th = 'nd';
- } else if ((dayi % 10) == 3 && day.substr(0, 1) != '1') {
- th = 'rd';
- }
- if (day.substr(0, 1) == '0') {
- day = day.substr(1);
- }
- return mon + ' ' + day + th + (thisyear != year ? ', ' + year : '');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement