Nodejs Date Value Check isValid()

Here you can find the source of isValid()

Method Source Code

Date.prototype.isValid = function() {
  return this.getTime() === this.getTime();
};

function twoDigits(value) {
  if (value < 10) {
    return '0' + value;
  }//from   w ww. j  a  v a  2s. c om
  return value;
}

exports.getMyDate = function(timestamp) {
  var date = new Date(timestamp * 1000);

  return date.getFullYear()
    + '-' + date.getMonth()
    + '-' + date.getDate();
}

exports.time = function() {
  var date = new Date();

  return date.valueOf() / 1000;
}

Related

  1. isToDay()
    Date.prototype.isToDay =function(){
        var today = new Date();
        return today.toDateString() == this.toDateString();
    };
    
  2. isToday()
    Date.prototype.isToday = function(){
      const today = new Date();
      return this.getYear() === today.getYear() &&
        this.getMonth() === today.getMonth() &&
        this.getDate() === today.getDate();
    };
    
  3. isToday()
    Date.prototype.isToday = function() {
      return this.toLocaleDateString() === new Date().toLocaleDateString();
    
  4. isToday()
    Date.prototype.isToday = function() {
        var today = new Date();
        return today.getYear() == this.getYear()
                && today.getMonth() == this.getMonth()
                && today.getDate() == this.getDate();
    };
    
  5. isToday()
    Date.prototype.isToday = function() {
        var today = new Date();
        return (today.getFullYear() == this.getFullYear() && today.getMonth() == this.getMonth() && today.getDate() == this.getDate());
    };
    
  6. isValid(y, m, d)
    Date.isValid = function(y, m, d) {
        var date = new Date(y, m - 1, d);
        return (date.getFullYear() == y && date.getMonth() + 1 == m && date.getDate() == d);
    
  7. isValidDate(date)
    Utils.isValidDate = function(date) { 
        var bits = date.split('-');
        var d = new Date(bits[0], bits[1] - 1, bits[2]);
        return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[2]);
    
  8. isValidDate(year, month, day)
    function isValidDate(year, month, day) {
      var days = new Array (31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
         if(year%4==0 && year%100 !=0 || year%400==0)
           days[1]=29;
         else
           days[1]=28;
         if(month < 1 || month > 12)
           return false;
         if(day > days[month-1] || day < 1)
    ...