Nodejs String to Date Convert getDate()

Here you can find the source of getDate()

Method Source Code

String.prototype.getDate = function() {
    return this.toDate().getDate();
}

Related

  1. toDate(pattern = 'YYYY-MM-DD')
    String.prototype.toDate = function (pattern = 'YYYY-MM-DD') {
        let date = new Date()
        if (pattern.indexOf("YYYY") > -1) {
            const yearIndex = pattern.indexOf("YYYY")
            date.setFullYear(this.substring(yearIndex,yearIndex+4))
        if(pattern.indexOf("MM")>-1){
            const monthIndex = pattern.indexOf("MM")
            date.setMonth(this.substring(monthIndex,monthIndex+2)-1)
    ...
    
  2. toDate(str)
    String.prototype.toDate = function(str) {
        var m = this.match(/(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/);
        return new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]);
    
  3. toDateFormat(format)
    String.prototype.toDateFormat = function (format) {
        return this.parseToDate().toDateFormat(format);
    };
    
  4. toDateFromAspNet()
    if (!window.console) {
        console = {
            log: function (msg) {
        };
    };
    String.prototype.toDateFromAspNet = function () {
        var dte = eval("new " + this.replace(/\
        dte.setMinutes(dte.getMinutes() - dte.getTimezoneOffset());
    ...
    
  5. toDateFromAspNet()
    String.prototype.toDateFromAspNet = function () {
        var dte = eval("new " + this.replace(/\
        dte.setMinutes(dte.getMinutes() - dte.getTimezoneOffset());
        return dte;
    };
    
  6. 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) {
    ...
    
  7. getDateString()
    Date.prototype.getDateString = function () {
       return this.getFullYear() + '/' + this.getMonth2() + '/' + this.getDate2();
    };
    Date.prototype.addDays = function (days) {
        this.setDate(this.getDate() + days);
        return this;
    };
    Date.prototype.getDate2 = function () {
       var date = this.getDate();
    ...
    
  8. getDateString()
    Date.prototype.getDateString = function () {
       return this.getFullYear() + '/' + this.getMonth2() + '/' + this.getDate2();
    };
    
  9. 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());
    ...