Nodejs Date Get getDateOrdinal()

Here you can find the source of getDateOrdinal()

Method Source Code

Date.prototype.getDateOrdinal = function()
{
  var n = this.getDate();

  var ord = 'th';

  if (n % 10 == 1 && n % 100 != 11)
  {/*www.  j  a v a2 s  . c o m*/
    ord = 'st';
  }
  else if (n % 10 == 2 && n % 100 != 12)
  {
    ord = 'nd';
  }
  else if (n % 10 == 3 && n % 100 != 13)
  {
    ord = 'rd';
  }

  return ord;
};

Related

  1. getDST()
    Date.prototype.getDST = function() {
        return this.getTimezoneOffset() - this.getStdTimezone();
    
  2. getDate2()
    Date.prototype.getDate2 = function () {
       var date = this.getDate();
       return (date < 10 ? '0' : '') + date;
    };
    
  3. getDateDiff(difference)
    function getDateDiff(difference) {
      var ret    = {};
      ret.days  = Math.floor(difference / 1000 / 60 / 60 / 24);
      ret.hours  = Math.floor(difference / 1000 / 60 / 60 - (24 * ret.days));
      ret.mins  = Math.floor(difference / 1000 / 60 - (24 * 60 * ret.days) - (60 * ret.hours));
      ret.secs  = Math.floor(difference / 1000 - (24 * 60 * 60 * ret.days) - (60 * 60 * ret.hours) - (60 * ret.mins));
      return ret;
    
  4. getDateDifference(otherDate)
    Date.prototype.getDateDifference = function(otherDate){
      var oneDay = 1000*3600*24;
      var d = new Date(+this);
      d.setHours(0,0,0,0);
      otherDate.setHours(0,0,0,0);
      var timeDiff = d.getTime() - otherDate.getTime();
      return Math.floor(timeDiff/oneDay);
    
  5. getDateOffset(target)
    Date.prototype.getDateOffset = function(target) {
        var milliSeconds = target.getTime() - this.getTime();
        return Math.ceil(milliSeconds/1000/60/60/24);
    };
    
  6. getDateParts()
    var convertMonthIndexToStr = function(monthIndex) {
      var map = [
        'January', 'February', 'March', 'April',
        'May', 'June', 'July', 'August',
        'September', 'October', 'November', 'December'
      ];
      return map[monthIndex];
    var convertDayOfWeekIndexToStr = function(dayOfWeekIndex) {
    ...
    
  7. getDateStamp()
    Date.prototype.getDateStamp = function() {
      let month = this.getMonth()+1;
      let day = this.getDate();
      return [this.getFullYear(),
        (month > 9 ? '' : '0') + month,
        (day > 9 ? '' : '0') + day
      ].join('');
    };
    
  8. getDisplayDate()
    Date.prototype.getDisplayDate = function()
      return this.getDate() > 9 ? "" : "0" + this.getDate();
    };
    Date.prototype.getDisplayMonth = function()
      return this.getMonth() > 9 ? "" : "0" + this.getMonth();
    };
    Date.prototype.addMilliseconds = function(count)
    ...
    
  9. getExcelTS()
    Date.prototype.getExcelTS = function(){
      var epoch = new Date(1899,11,31);
      var dt = this.setDate(this.getDate()+1);
      var ts = (dt-epoch)/(1000*60*60*24);
      return ts;
    };