Get Date Ordinal - Node.js Date

Node.js examples for Date:Date Calculation

Description

Get Date Ordinal

Demo Code

Date.prototype.getDateOrdinal = function() {
  var n = this.getDate();
  var ord = "th";
  if (n % 10 == 1 && n % 100 != 11) {
    ord = "st";/*from w  w w  . j  a  v  a 2s.  c  o  m*/
  } else if(n % 10 == 2 && n % 100 != 12) {
    ord = "nd";
  } else if(n % 10 == 3 && n % 100 != 13) {
    ord = "rd";
  }
  return ord;
};

Related Tutorials