Nodejs Date Format format(format)

Here you can find the source of format(format)

Method Source Code

Date.prototype.format = function(format) {
    // set default format if function argument not provided
    format = format || 'YYYY-MM-DD hh:mm';

    var zeropad = function (number, length) {
            number = number.toString();
            length = length || 2;
            while (number.length < length)
                number = '0' + number;
            return number;
        },//from w  w  w.ja  va2s .  c  o  m
    // here you can define your formats
        formats = {
            YYYY: this.getFullYear(),
            MM: zeropad(this.getMonth() + 1),
            DD: zeropad(this.getDate()),
            hh: zeropad(this.getHours()),
            mm: zeropad(this.getMinutes())
        },
        pattern = '(' + Object.keys(formats).join(')|(') + ')';

    return format.replace(new RegExp(pattern, 'g'), function (match) {
        return formats[match];
    });
}

export default Date

Related

  1. format(format)
    Date.prototype.format = function (format) {
      var hours = this.getHours();
      var ttime = "AM";
      if (format.indexOf("t") > -1 && hours > 12) {
        hours = hours - 12;
        ttime = "PM";
      var o = {
        "M+": this.getMonth() + 1, 
    ...
    
  2. format(format)
    Date.prototype.format =function(format)
        var o = {
            "M+" : this.getMonth()+1, 
            "d+" : this.getDate(),    
            "h+" : this.getHours(),   
            "m+" : this.getMinutes(), 
            "s+" : this.getSeconds(), 
            "q+" : Math.floor((this.getMonth()+3)/3),  
    ...
    
  3. format(format)
    Date.prototype.format = function(format)
      var o = { 
        "M+" : this.getMonth()+1, 
        "d+" : this.getDate(),    
        "h+" : this.getHours(),   
        "m+" : this.getMinutes(), 
        "s+" : this.getSeconds(), 
        "q+" : Math.floor((this.getMonth()+3)/3),  
    ...
    
  4. format(format)
    Date.prototype.format = function(format)  
      var o = {  
      "M+" : this.getMonth() + 1,  
      "d+" : this.getDate(),  
      "h+" : this.getHours(),  
      "m+" : this.getMinutes(),  
      "s+" : this.getSeconds(),  
      "q+" : Math.floor((this.getMonth() + 3) / 3),  
    ...
    
  5. format(format)
    Date.prototype.format = function(format)
        var o = {
          "M+" : this.getMonth()+1, 
          "d+" : this.getDate(),    
          "h+" : this.getHours(),   
          "m+" : this.getMinutes(), 
          "s+" : this.getSeconds(), 
          "q+" : Math.floor((this.getMonth()+3)/3),  
    ...
    
  6. format(format)
    Date.prototype.format = function(format){
      if(typeof(format)=="undefined")
        format="dd/MM/yyyy";
        var o = {
            "M+": this.getMonth() + 1, 
            "d+": this.getDate(), 
            "h+": this.getHours(), 
            "m+": this.getMinutes(), 
            "s+": this.getSeconds(), 
    ...
    
  7. format(format)
    function random(min, max) {
        return Math.round(Math.random() * (max - min) + min);
    Date.prototype.format = function(format) {
      var o = {
        "M+" : this.getMonth()+1, 
        "d+" : this.getDate(),    
        "h+" : this.getHours(),   
        "m+" : this.getMinutes(), 
    ...
    
  8. format(format)
    var mainModule = angular.module("mainModule", []);
    angular.element(document).ready(function() {
      angular.bootstrap(document, ["mainModule"]);
    });
    Date.prototype.format = function (format) {  
        var o = {  
            "M+": this.getMonth() + 1,  
            "d+": this.getDate(),  
            "h+": this.getHours(),  
    ...
    
  9. format(format)
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
    ...