Nodejs String to Date Convert getDateString()

Here you can find the source of getDateString()

Method Source Code

Date.prototype.getDateString = function () {
   return this.getFullYear() + '/' + this.getMonth2() + '/' + this.getDate2();
};

Date.prototype.addDays = function (days) {
    this.setDate(this.getDate() + days);
    return this;/*from   w ww.j  ava  2s.c  o  m*/
};

Date.prototype.getDate2 = function () {
   var date = this.getDate();
   return (date < 10 ? '0' : '') + date;
};

Date.prototype.getMonth2 = function () {
   var month = this.getMonth() + 1;
   return (month < 10 ? '0' : '') + month;
};

Date.prototype.toDateFormat = function (format) {
    format = format || 'yyyy/MM/dd';

    return format.toLowerCase()
        .replace(/yyyy/g, this.getFullYear())
        .replace(/yy/g, this.getFullYear().toString().substr(2,2))
        .replace(/mm/g, this.getMonth2())
        .replace(/m/g, this.getMonth() + 1)
        .replace(/dd/g, this.getDate2())
        .replace(/d/g, this.getDate());
};

Number.prototype.toDateFormat = function (format) {
   return new Date(this).toDateFormat(format);
};

Number.prototype.to2Digits = function () {
   return this.toFixed(2).toString().replace('.', ',');
};

String.prototype.to2Digits = function () {
   return this == '' ? '-' : parseFloat(this).to2Digits();
};

Related

  1. toDateFormat(format)
    String.prototype.toDateFormat = function (format) {
        return this.parseToDate().toDateFormat(format);
    };
    
  2. toDateFromAspNet()
    if (!window.console) {
        console = {
            log: function (msg) {
        };
    };
    String.prototype.toDateFromAspNet = function () {
        var dte = eval("new " + this.replace(/\
        dte.setMinutes(dte.getMinutes() - dte.getTimezoneOffset());
    ...
    
  3. toDateFromAspNet()
    String.prototype.toDateFromAspNet = function () {
        var dte = eval("new " + this.replace(/\
        dte.setMinutes(dte.getMinutes() - dte.getTimezoneOffset());
        return dte;
    };
    
  4. getDate()
    String.prototype.getDate = function() {
        return this.toDate().getDate();
    
  5. getDateString()
    Date.prototype.getDateString = function(){
      var S = this.getSeconds(),
          M = this.getMinutes(), H = this.getHours(),
          dd = this.getDate(), mm = this.getMonth()+1, 
          yyyy = this.getFullYear();
      if(dd<10){
        dd ='0'+dd
      if(mm<10) {
    ...
    
  6. getDateString()
    Date.prototype.getDateString = function () {
       return this.getFullYear() + '/' + this.getMonth2() + '/' + this.getDate2();
    };
    
  7. getDateString(str)
    Date.prototype.getDateString = function(str)
      var dnames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
          'Thursday', 'Friday', 'Saturday', 'Sunday'];
      var mnames = ['January', 'February', 'March', 'April',
          'May', 'June', 'July', 'August', 'September',
          'October', 'Novemeber', 'December'];
      str = str.replace('%day', dnames[this.getDay()]);
      str = str.replace('%date', this.getDate());
    ...