Nodejs Date Convert toCommonCase()

Here you can find the source of toCommonCase()

Method Source Code

Date.prototype.toCommonCase=function(){
    var xYear=this.getYear();
    xYear=xYear+1900;//from  ww  w .j  av  a2  s.c o m
    
    var xMonth=this.getMonth()+1;
    if(xMonth<10){
        xMonth="0"+xMonth;
    }

    var xDay=this.getDate();
    if(xDay<10){
        xDay="0"+xDay;
    }

    var xHours=this.getHours();
    if(xHours<10){
        xHours="0"+xHours;
    }

    var xMinutes=this.getMinutes();
    if(xMinutes<10){
        xMinutes="0"+xMinutes;
    }

    var xSeconds=this.getSeconds();
    if(xSeconds<10){
        xSeconds="0"+xSeconds;
    }
    return xYear+"-"+xMonth+"-"+xDay+" "+xHours+":"+xMinutes+":"+xSeconds;
}

Related

  1. dateToJSON()
    Date.prototype.dateToJSON = function() {
      return this.toJSON().substring(0, 11);
    };
    
  2. dateToStr()
    Date.prototype.dateToStr = function() {
        var yil = this.getUTCFullYear();
        var ay = parseInt((this.getMonth() + 1) / 10) == 0 ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1);
        var gun = parseInt(this.getDate() / 10) == 0 ? ("0" + this.getDate()) : this.getDate();
        var saat = parseInt(this.getHours() / 10) == 0 ? ("0" + this.getHours()) : this.getHours();
        var dakika = parseInt(this.getMinutes() / 10) == 0 ? ("0" + this.getMinutes()) : this.getMinutes();
        return String(yil + ay + gun + saat + dakika);
    
  3. dateToYMD()
    Date.prototype.dateToYMD = function() {
        var d = this.getDate();
        var m = this.getMonth() + 1;
        var y = this.getFullYear();
        return  y + (m<=9 ? '0' + m : m) +  (d <= 9 ? '0' + d : d);
    
  4. toAmPm()
    Date.prototype.toAmPm = function () {
        var hours = this.getHours();
        var minutes = this.getMinutes();
        var ampm = hours >= 12 ? 'pm' : 'am';
        hours = hours % 12;
        hours = hours ? hours : 12;
        minutes = minutes < 10 ? '0' + minutes : minutes;
        return hours + ':' + minutes + ampm;
    };
    ...
    
  5. toApiDate()
    function twoDigits(d) {
        if(0 <= d && d < 10) return "0" + d.toString();
        if(-10 < d && d < 0) return "-0" + (-1*d).toString();
        return d.toString();
    Date.prototype.toApiDate = function() {
        return this.getUTCFullYear() + "" + twoDigits(1 + this.getUTCMonth()) + "" + twoDigits(this.getUTCDate()); 
    };
    Date.prototype.toTrDate = function() {
    ...
    
  6. toCustomFormat()
    var prependZero = function(num) {
      return (num < 10)? ("0" + num) : num;
    Date.prototype.toCustomFormat = function() {
      var h = this.getHours(),
          h_12hr = (h % 12),
          hh = prependZero((h_12hr == 0)? 12 : h_12hr),
          mm = prependZero(this.getMinutes()),
          ss = prependZero(this.getSeconds()),
    ...
    
  7. toDate()
    Date.prototype.toDate = function(){
      return new Date(this.getFullYear(), this.getMonth(), this.getDate());
    
  8. 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());
    ...
    
  9. toDateInputValue(()
    Date.prototype.toDateInputValue = (function() {
      var local = new Date(this);
      local.setMinutes(this.getMinutes() - this.getTimezoneOffset())
      return local.toJSON().slice(0,10);