Nodejs Date Get getFormat()

Here you can find the source of getFormat()

Method Source Code

/*//from w  ww  . j  a  va 2s .  c  om
 * Generic Javascript Utility Functions
 *
 * Copyright (c) 2011, Tom Swindell.
 *
 * This program is licensed under the terms and conditions of the
 * Apache License, version 2.0.  The full text of the Apache License is at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */

Date.prototype.getFormat = function()
{
    return (this.getDate() < 10 ? '0' : '') + this.getDate() + '/' +
           (this.getMonth() < 10 ? '0' : '') + this.getMonth() + '/' +
           this.getFullYear() +
           ' | ' +
           (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' +
           (this.getMinutes() < 10 ? '0' : '') + this.getMinutes() + ':' +
           (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
}

function friendlyDuration(start, end)
{
    var duration = Math.floor(((new Date(end)) - (new Date(start))) / 1000);
    var minutes = Math.floor(duration / 60);
    var seconds = duration % 60;

    return (minutes < 10 ? '0' : '') + minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
}

Related

  1. getDateOrdinal()
    Date.prototype.getDateOrdinal = function()
      var n = this.getDate();
      var ord = 'th';
      if (n % 10 == 1 && n % 100 != 11)
        ord = 'st';
      else if (n % 10 == 2 && n % 100 != 12)
    ...
    
  2. 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) {
    ...
    
  3. 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('');
    };
    
  4. 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)
    ...
    
  5. 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;
    };
    
  6. getFormat()
    Date.prototype.getFormat = function()
        return (this.getDate() < 10 ? '0' : '') + this.getDate() + '/' +
               (this.getMonth() < 10 ? '0' : '') + this.getMonth() + '/' +
               this.getFullYear() +
               ' | ' +
               (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' +
               (this.getMinutes() < 10 ? '0' : '') + this.getMinutes() + ':' +
               (this.getSeconds() < 10 ? '0' : '') + this.getSeconds();
    ...
    
  7. getFormated()
    Date.prototype.getFormated = function() {
      function pad(number) {
        if (number < 10) return '0' + number;
        return number;
      var d = this.getFullYear() + '-' + pad(this.getMonth() + 1) + '-' + pad(this.getDate());
      var t = pad(this.getHours()) + ':' + pad(this.getMinutes()) + ':' + pad(this.getSeconds());
      return d + ' ' + t;
    };
    ...
    
  8. getFromFormat(format)
    Date.prototype.getFromFormat = function(format) {
        var yyyy = this.getFullYear().toString();
        format = format.replace(/yyyy/g, yyyy)
        var mm = (this.getMonth()+1).toString(); 
        format = format.replace(/mm/g, (mm[1]?mm:"0"+mm[0]));
        var dd  = this.getDate().toString();
        format = format.replace(/dd/g, (dd[1]?dd:"0"+dd[0]));
        var hh = this.getHours().toString();
        format = format.replace(/hh/g, (hh[1]?hh:"0"+hh[0]));
    ...
    
  9. getFullDate()
    Date.prototype.getFullDate = function(){  
      if (this.getDate() < 10) {
        return '0' + this.getDate();
      return this.getDate();
    };