Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function formatDate(date) {
  2.             var ds = date.toDateString().split(/ /),
  3.                 mon = monthDict[date.getMonth()],
  4.                 day = date.getDate()+'',
  5.                 dayi = parseInt(day),
  6.                 year = date.getFullYear(),
  7.                 thisyear = (new Date()).getFullYear(),
  8.                 th = 'th';
  9.            
  10.             // anti-'th' - but don't do the 11th, 12th or 13th
  11.             if ((dayi % 10) == 1 && day.substr(0, 1) != '1') {
  12.                 th = 'st';
  13.             } else if ((dayi % 10) == 2 && day.substr(0, 1) != '1') {
  14.                 th = 'nd';
  15.             } else if ((dayi % 10) == 3 && day.substr(0, 1) != '1') {
  16.                 th = 'rd';
  17.             }
  18.            
  19.             if (day.substr(0, 1) == '0') {
  20.                 day = day.substr(1);
  21.             }
  22.            
  23.             return mon + ' ' + day + th + (thisyear != year ? ', ' + year : '');
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement