Nodejs Date Convert toDateInputValue(()

Here you can find the source of toDateInputValue(()

Method Source Code

// Lifted this idea (with slight modifications) for easily outputting a date value acceptable for use in a date input from
// http://stackoverflow.com/questions/6982692/html5-input-type-date-default-value-to-today

// I believe in attributing ideas, and when I need a quick solution if I can find one that
// someone has already done well, I'm generally happy to learn, understand, and then use it, so
// I can more quickly move to the next challenge.

// Extend Date to output a value acceptable for date input field
Date.prototype.toDateInputValue = (function() {
  var local = new Date(this);
  local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
  return local.toISOString().substr(0,10);
});//from  w  w w .j av a2 s. co m

Related

  1. toDate()
    Date.prototype.toDate = function(){
      return new Date(this.getFullYear(), this.getMonth(), this.getDate());
    
  2. toDateFormat(format)
    Date.prototype.toDateFormat = function (format) {
        format = format || "yyyy/mm/dd";
        return format.toLowerCase()
            .replace(/yyyy/g, this.getFullYear())
            .replace(/yy/g, this.getYear())
            .replace(/mm/g, this.getMonth2())
            .replace(/m/g, this.getMonth() + 1)
            .replace(/dd/g, this.getDate2())
            .replace(/d/g, this.getDate());
    ...
    
  3. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
      var local = new Date(this);
      local.setMinutes(this.getMinutes() - this.getTimezoneOffset())
      return local.toJSON().slice(0,10);
    
  4. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
      var local = new Date(this);
      local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
      return local.toISOString().substr(0,10);
    });
    
  5. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
        var local = new Date(this);
        local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
        return local.toJSON().slice(0,10);
    });
    
  6. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
        var local = new Date(this);
        local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
        return local.toJSON().slice(0,10);
    });
    
  7. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
      var local = new Date(this);
      local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
      return local.toJSON().slice(0,10);
    });
    
  8. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
        var local = new Date(this);
        local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
        return local.toJSON().slice(0, 10);
    });
    
  9. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
      var local = new Date();
      return local.toJSON().slice(0,10);
    });