Javascript Date yyyymmdd()

Description

Javascript Date yyyymmdd()


Date.prototype.yyyymmdd = function() {
    var yyyy = this.getFullYear().toString();
    var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
    var dd  = this.getDate().toString();
    return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]); // padding
};

Javascript Date yyyymmdd()

define(function() {

Date.prototype.yyyymmdd = function() {

    var yyyy = this.getFullYear().toString();
    var mm = (this.getMonth()+1).toString();
    var dd  = this.getDate().toString();

    return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};

Date.prototype.unixtime = function() {
    return Math.round(this.getTime() / 1000 );
};

});/*from   www. j ava2s .c om*/

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
    // adapted from http://stackoverflow.com/a/3067896
    var yyyy = this.getFullYear();
    var mm_aux = this.getMonth() + 1;  // getMonth() is zero-based
    var mm = mm_aux < 10 ? "0" + mm_aux : mm_aux;
    var dd_aux = this.getDate();
    var dd  = dd_aux < 10 ? "0" + dd_aux : dd_aux;
    return "".concat(yyyy, "-", mm, "-", dd);
};

Javascript Date yyyymmdd()

'use strict';/*from w  w w  .  java 2s .  c  om*/

// Format Date object
Date.prototype.yyyymmdd = function() {

  var yyyy = this.getFullYear().toString();
  var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
  var dd  = this.getDate().toString();

  return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
    var mm = this.getMonth() + 1; // getMonth() is zero-based
    var dd = this.getDate();

    return [this.getFullYear(), !mm[1] && '0', mm, !dd[1] && '0', dd, this.getHours(), this.getMinutes(), this.getSeconds()].join(''); // padding
};

Javascript Date yyyymmdd()

'use strict';/*from   www .j  a  va  2 s . c  o m*/

Date.prototype.yyyymmdd = function (){
 var yyyymmdd = '';
 yyyymmdd += this.getFullYear();
 yyyymmdd += '-';
 if (this.getMonth()+1 >= 10){
  yyyymmdd += (this.getMonth() +1);
 }
 else {
  yyyymmdd += ('0' + (this.getMonth() + 1));
 }
 yyyymmdd += '-';
 if (this.getDate() >=0){
  yyyymmdd += this.getDate();
 }
 else {
  yyyymmdd += ('0' + this.getDate());
 }
 return yyyymmdd;
}

var clock = function(){
 var date = new Date();
 console.log(date);
 setTimeout(clock,1000);
}

clock();

Javascript Date yyyymmdd()

var monthNames = [
"Jan", // ww  w .  j  a va  2 s.c  o m
"Feb", 
"Mar", 
"Apr", 
"May", 
"Jun",
"Jul", 
"Aug", 
"Sep", 
"Oct", 
"Nov", 
"Dec"
];

Date.prototype.yyyymmdd = function() {
  var mm = this.getMonth(); // getMonth() is zero-based
  var dd = this.getDate();

  return [
     (mm>9 ? '' : '0') + monthNames[mm],
           (dd>9 ? '-' : '-0') + dd,
          "-" + this.getFullYear()
         ].join('');
};

var date = new Date();
console.log(date.yyyymmdd());

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
 var yyyy = this.getFullYear().toString();
 var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
 var dd  = this.getDate().toString();
 return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
};


function stringToTime(str){
  if (str === ""){
    return ""
  };/*from w ww  .  jav  a  2s .co m*/
  var ampm = "AM";
  var hhmmss = str.match(/T(.*)Z/)[1];

  var hour = Number(hhmmss.split(":")[0]);
  if (hour > 12){
    hour = hour - 12;
    ampm = "PM";
  };
  var min = hhmmss.split(":")[1];
  return hour.toString() + ":" + min + " " + ampm;
};

Javascript Date yyyymmdd()

const execSync = require('child_process').execSync;
Date.prototype.yyyymmdd = function() {
  var mm = this.getMonth() + 1; // getMonth() is zero-based
  var dd = this.getDate();
  mm = mm < 10 ? '0'+ mm : mm;
  dd = dd < 10 ? '0'+ dd : dd;
  return [this.getFullYear(), mm, dd].join(''); // padding
};

var now = new Date();



for (var d = new Date(2016, 7, 1); d <= now; d.setDate(d.getDate() + 1)) {
    let date = new Date(d);
    execSync(`wget http://api.wunderground.com/api/ae155f8b19bf54f0/history_${date.yyyymmdd()}/q/CA/Yerevan.json -O weather/history_${date.yyyymmdd()}.json`);
}

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
   var yyyy = this.getFullYear().toString();
   var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
   var dd  = this.getDate().toString();
   return yyyy + '-' + (mm[1]?mm:'0'+mm[0]) + '-' + (dd[1]?dd:'0'+dd[0]); // padding
};

Javascript Date yyyymmdd()

if (typeof Object.create !== 'function') {
    Object.create = function (o) {
        /**//  ww w.  j  a  v  a  2 s  .co  m
         * @constructor
         */
        var F = function () {};
        F.prototype = o;
        return new F();
    };
}

Date.prototype.yyyymmdd = function() {
    var yyyy = this.getFullYear().toString();
    var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
    var dd  = this.getDate().toString();
    return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};

Javascript Date yyyymmdd()

var net = require('net');
var port = process.argv[2];

Date.prototype.yyyymmdd = function() {
 var yyyy = this.getFullYear().toString();
 var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
 var dd  = this.getDate().toString();
 var hh = this.getHours().toString();
 var minute = this.getMinutes().toString();
 return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]) + ' ' +
  (hh[1]?hh:"0"+hh[0]) + ':' + (minute[1]?minute:"0"+minute[0]); // padding
};
var server = net.createServer(function (socket) {
 var date = new Date();
 socket.end(date.yyyymmdd() + '\n');
});//from www . j ava  2  s  .  co m
server.listen(port);

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
    var yyyy = this.getFullYear().toString()
       , mm = (this.getMonth()+1).toString() // getMonth() is zero-based
       , dd  = this.getDate().toString();
    /*from ww  w  .j  av  a 2 s  .c  om*/
    return yyyy +"-"+ (mm[1]?mm:"0"+mm[0]) +"-"+ (dd[1]?dd:"0"+dd[0]);     
};

Javascript Date yyyymmdd()

// make Date format be NYT friendly
Date.prototype.yyyymmdd = function() {
  var mm = ("0" + (this.getMonth() + 1)).slice(-2);
  var dd = ( "0" + this.getDate()).slice(-2);
  return [this.getFullYear(), mm, dd].join('');
};

Javascript Date yyyymmdd()

// Extend Date constructor with a 'yyyymmdd' formatting method
// (thanks to http://stackoverflow.com/users/318563/o-o)

Date.prototype.yyyymmdd = function() {
 var yyyy = this.getFullYear().toString();
 var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
 var dd  = this.getDate().toString();
 return yyyy + (mm[1]?mm:'0'+mm[0]) + (dd[1]?dd:'0'+dd[0]); // padding
};

// get today's date in yyyymmdd format

var todaysDate = new Date().yyyymmdd();

Javascript Date yyyymmdd()

Date.prototype.yyyymmdd = function() {
    var yyyy = this.getFullYear().toString();
    var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
    var dd  = this.getDate().toString();
    return yyyy +"-"+ (mm[1]?mm:"0"+mm[0]) +"-"+ (dd[1]?dd:"0"+dd[0]); // padding
};

Javascript Date yyyymmdd()

//prototype// www .ja v a 2  s. co m
Date.prototype.yyyymmdd = function() {
    var today = new Date();
    var tomorrow = new Date();
    tomorrow.setDate(today.getDate() + 1);

    var mm = tomorrow.getMonth() + 1;
    var dd = tomorrow.getDate();

    return [this.getFullYear(), !mm[1] && '-', mm, !dd[1] && '-', dd].join('');
};



PreviousNext

Related