Nodejs Time Calculate p8DeDate(time)

Here you can find the source of p8DeDate(time)

Method Source Code

Date.prototype.p8DeDate = function(time) {
  var d = this;/*from   w  ww  .j a va 2 s.  co m*/
  function pad(n) {
    return n < 10 ? '0' + n : n;
  }
  function pad3(n) {
    if(n < 10) {
       return '00' + n;
    } else if(n < 100) {
      return '0' + n;
    } else {
      return n;
    }
  }

  var fdate =   pad(d.getUTCDate()) + '.' + 
    pad(d.getUTCMonth() + 1) + '.' +
    d.getUTCFullYear();
  
  if(time === true) {
    fdate += " " + pad(d.getUTCHours()) + ':' + 
    pad(d.getUTCMinutes());
  }
  
  return fdate;
};

Related

  1. getTimeAmPm()
    Date.prototype.getTimeAmPm = function () {
      let hours = this.getHours();
      let minutes = this.getMinutes();
      let ampm = hours >= 12 ? 'pm' : 'am';
      hours = hours % 12;
      hours = hours ? hours : 12; 
      minutes = minutes < 10 ? '0' + minutes : minutes;
      let strTime = hours + ':' + minutes + '' + ampm;
      return strTime;
    ...
    
  2. getTimeShift()
    Date.prototype.getTimeShift = function() {
        return this.getTimezoneOffset() < this.stdTimezoneOffset()?3:2;
    };
    
  3. getUnixTime()
    getQueryString = function (field, url) {
        var href = url || window.location.href;
        var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
        var string = reg.exec(href);
        return string ? string[1] : null;
    };
    Date.prototype.getUnixTime = function () {
        return this.getTime() / 1000 | 0
    };
    ...
    
  4. halfHoursUntil(otherTime)
    Date.prototype.halfHoursUntil = function(otherTime) {
      var hour = new Date(this);
      var numberOfHalfHours = 0;
      while (hour < otherTime) {
        numberOfHalfHours++;
        hour.addHalfHour();
      return numberOfHalfHours;
    };
    ...
    
  5. onlyTime()
    Date.prototype.onlyTime = function () {
      return this.toTimeString().split(" ")[0];
    };
    
  6. prettyDate(time)
    function prettyDate(time) {
        var date = new Date().setISO8601(time || "");
        console.log('date: ' + date);
        var diff = (((new Date()).getTime() - date.getTime()) / 1000);
        console.log('diff: ' + diff);
        var day_diff = Math.floor(diff / 86400);
        console.log('daydiff: ' + day_diff);
        if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) {
          console.log('some shit went bad');
    ...
    
  7. setTimeToNow()
    Date.prototype.setTimeToNow = function () 
        var n = Date.relativeTo || new Date();
        this.setHours(n.getHours());
        this.setMinutes(n.getMinutes());
        this.setSeconds(n.getSeconds());
        this.setMilliseconds(n.getMilliseconds());
        return this;
    
  8. time()
    Date.prototype.time = function () {
        return this.getHours().zfill(2) + ":" + this.getMinutes().zfill(2) + ":" + this.getSeconds().zfill(2);
    };
    
  9. time()
    Date.prototype.time = function(){
      var hours = this.getHours();
      if (hours === 0 || hours === 24) hours = 12;
      if (hours > 12) hours -= 12;
      var minutes = this.getMinutes();
      if (minutes < 10) minutes = "0" + minutes;
      var ampm = this.getHours() >= 12 ? "pm" : "am";
      return "" + hours + ":" + minutes + ampm;