Nodejs Date Format format(formatStr)

Here you can find the source of format(formatStr)

Method Source Code

/* JS *///from w ww  . j  av a2 s .  c om
Date.prototype.format = function(formatStr)   
{   
    var str = formatStr;   
    var Week = ['?','?','?','?','?','?','?'];  
  
    str=str.replace(/yyyy|YYYY/,this.getFullYear());   
    str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));   
  
    str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());   
    str=str.replace(/M/g,this.getMonth());   
  
    str=str.replace(/w|W/g,Week[this.getDay()]);   
  
    str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());   
    str=str.replace(/d|D/g,this.getDate());   
  
    str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());   
    str=str.replace(/h|H/g,this.getHours());   
    str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());   
    str=str.replace(/m/g,this.getMinutes());   
  
    str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());   
    str=str.replace(/s|S/g,this.getSeconds());   
  
    return str;   
}

Related

  1. format(format)
    Date.prototype.format = function(format) {
      var self = this;
      var h = self.getHours();
      var m = self.getMinutes().toString();
      var s = self.getSeconds().toString();
      var M = (self.getMonth() + 1).toString();
      var yyyy = self.getFullYear().toString();
      var yy = self.getYear().toString();
      var d = self.getDate().toString();
    ...
    
  2. format(format)
    var fs = require('fs');
    var readline = require('readline');
    Date.prototype.format = function(format) {
      var o = {
        "M+" : this.getMonth()+1, 
        "d+" : this.getDate(),    
        "h+" : this.getHours(),   
        "m+" : this.getMinutes(), 
        "s+" : this.getSeconds(), 
    ...
    
  3. format(format,date)
    Date.prototype.format = function(format,date){
        if(!format || typeof format !== 'string'){
        throw new Error('format is undefiend or type is Error');
      date = date instanceof Date? date : (typeof date === 'number'|| typeof date === 'string')? new Date(date): new Date();
      var formatReg = {
        'y+': date.getFullYear(),
        'M+': date.getMonth()+1,
        'd+': date.getDate(),
    ...
    
  4. format(format,value)
    Date.prototype.format = function (format,value) {
      if (!format) {
        format = "yyyy-MM-dd hh:mm:ss";
      if(value==''||value==null){
        return '';
      var strdata=value.replace(/-/g,"/");
      var index=strdata.indexOf(".");
    ...
    
  5. format(format,value)
    Date.prototype.format = function (format,value) {
      if (!format) {
        format = "yyyy-MM-dd hh:mm:ss";
      if(value==''||value==null){
        return '';
      var strdata=value.replace(/-/g,"/");
      var index=strdata.indexOf(".");
    ...
    
  6. format(formatStr)
    Date.prototype.format = function(formatStr) {
        var str = formatStr;
        var Week = ['?','?','?','?','?','?','?'];
        str = str.replace(/yyyy|YYYY/,this.getFullYear());
        str = str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
        str = str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + this.getMonth());
        str = str.replace(/M/g,this.getMonth());
        str = str.replace(/w|W/g,Week[this.getDay()]);
        str = str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
    ...
    
  7. format(formatStr)
    Date.prototype.format= function(formatStr) 
    var date = this;
    var timeValues = function(){};
    timeValues.prototype = {
       year:function(){
        if(formatStr.indexOf("yyyy")>=0)
         return date.getYear();
    ...
    
  8. format(pattern)
    Date.prototype.format = function(pattern) {
      var returnValue = pattern;
      var format = {
        "y+": this.getFullYear(),
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
    ...
    
  9. format(pattern)
    Date.prototype.format = function(pattern)
      if(!pattern){
        pattern = "yyyy-MM-dd";
      var o =
        "M+" : this.getMonth() + 1, 
        "d+" : this.getDate(), 
    ...