Knockout.js format date item

前端 未结 5 1583
轻奢々
轻奢々 2020-12-15 03:49

In my view I wish to display a knockout.js binded field that contains a date. It is just a display field and not an input field. Something like below when

5条回答
  •  执笔经年
    2020-12-15 04:11

    Declare format function:

    Date.prototype.toFormattedDate = function () {
      var dd = this.getDate();
      if (dd < 10) dd = '0' + dd;
      var mm = this.getMonth() + 1;
      if (mm < 10) mm = '0' + mm;
      var yyyy = this.getFullYear();
      /* change format here */
      return String(mm + "/" + dd + "/" + yyyy);
    };
    

    And use it with the date strings as:

    
    

提交回复
热议问题