Nodejs Date Convert toLocalTime()

Here you can find the source of toLocalTime()

Method Source Code

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);/*from  w ww.  ja  va2 s  .c  o m*/

    return newDate;
};

Related

  1. toFormat(format)
    Date.prototype.toFormat = function (format) {
      format = format.replace(/H/, this.getHours());
      format = format.replace(/m/, this.getMinutes());
      format = format.replace(/s/, this.getSeconds());
      return format;
    };
    
  2. toISO8601()
    Date.prototype.toISO8601 = function() {
      function pad(n) {
        return n < 10 ? '0' + n : n;
      return this.getUTCFullYear() + '-' + pad(this.getUTCMonth() + 1) + '-' + pad(this.getUTCDate()) + 'T' + pad(this.getUTCHours())
       + ':' + pad(this.getUTCMinutes()) + ':' + pad(this.getUTCSeconds()) + 'Z';
    };
    
  3. 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;
    ...
    
  4. 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;
    };
    
  5. 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]); 
      };
    
  6. 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());
        };
    
  7. toLocaleJSON()
    Date.prototype.toLocaleJSON = function() {
      var t = this,
        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) + ' ' +
    ...
    
  8. 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){ 
    ...
    
  9. 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;