Nodejs Date Convert toLocaleJSON()

Here you can find the source of toLocaleJSON()

Method Source Code

/* To get time with locat settings. */
Date.prototype.toLocaleJSON = function() {
  var t = this,/*from w  w  w.  ja v a 2 s .  co m*/
    y = t.getFullYear(),
    M = t.getMonth() + 1,
    d = t.getDate(),
    h = t.getHours(),
    m = t.getMinutes(),
    s = t.getSeconds();
  return y + '/' + (M < 10 ? '0' + M : M) + '/' + (d < 10 ? '0' + d : d) + ' ' +
    (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
}

Related

  1. toISO8601()
    Date.prototype.toISO8601 = function() {    
        var s = [
              this.getFullYear()
            , Date.padZero(this.getMonth() + 1)
            , Date.padZero(this.getDate())
        ].join("-") + "T";
        s += this.getTimeString();
        s += this.getTimezoneOffsetString(true);
        return s;
    ...
    
  2. toISO8601(key)
    Date.prototype.toISO8601 = function (key) {
        function f(n) {
            return n < 10 ? '0' + n : n;
        function f2(n) {
            if(n < 10)
              return '00' + n;
            return n < 100 ? '0' + n : n;
        return isFinite(this.valueOf()) ?
               this.getUTCFullYear()   + '-' +
             f(this.getUTCMonth() + 1) + '-' +
             f(this.getUTCDate())      + 'T' +
             f(this.getUTCHours())     + ':' +
             f(this.getUTCMinutes())   + ':' +
             f(this.getUTCSeconds())   + '.' +
             f2(this.getUTCMilliseconds()) + '-0000' : null;
    };
    
  3. toInputFormat()
    Date.prototype.toInputFormat = 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]); 
      };
    
  4. toLocalTime()
    Date.prototype.toLocalTime = function() {
        const newDate = new Date(this.getTime()+this.getTimezoneOffset()*60*1000);
        let offset = this.getTimezoneOffset() / 60;
        const hours = this.getHours();
        if (this.dst()) offset--;
        newDate.setHours(hours - offset);
        return newDate;
    };
    
  5. toLocaleFormat(pattern)
    'use strict';
    Date.prototype.toLocaleFormat = Date.prototype.toLocaleFormat || function (pattern) {
            return pattern.replace(/%Y/g, this.getFullYear()).replace(/%m/g, (this.getMonth() + 1)).replace(/%d/g, this.getDate());
        };
    
  6. toLongintText()
    Date.prototype.toLongintText=function(){ 
      var m; 
      var d; 
      if(this.getMonth()<9){ 
      m="0"+(this.getMonth()+1); 
      }else{ 
      m=this.getMonth()+1; 
      if(this.getDate()<10){ 
    ...
    
  7. toOADate()
    Date.prototype.toOADate = function ()
      var jsDate = this || new Date();
      var timezoneOffset = jsDate.getTimezoneOffset() / (60 * 24);
      var msDateObj = (jsDate.getTime() / 86400000) + (25569 - timezoneOffset);
      return msDateObj;
    
  8. toRFC2822()
    Date.prototype.toRFC2822 = function() {    
        return [
              Date.DAYS[this.getDay()] + ","
            , Date.padZero(this.getDate())
            , Date.MONTHS[this.getMonth()]
            , this.getFullYear()
            , this.getTimeString()
            , this.getTimezoneOffsetString()
        ].join(" ");
    ...
    
  9. toRFC3339()
    Date.prototype.toRFC3339 = function()
      var year = this.getFullYear();
      var month = this.getMonth()+1;  
      var date = this.getDate();
      var hours = this.getHours();
      var mins = this.getMinutes();
      var secs = this.getSeconds();
      return (year+'-'+month+'-'+date+' '+hours+':'+mins+':'+secs);
    ...