Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

timezone offset to timezone in javascript

getGMT() {
    let gmtFigure = new Date().getTimezoneOffset() / -60;
    let gmtSign = gmtFigure >= 0 ? '+' : '-';
    let gmtlength = this.digits_count(gmtFigure);
    let gmt = 'GMT';
    if (gmtlength == 1) {
      gmt += gmtSign + '0' + Math.abs(gmtFigure);
    } else if (gmtlength > 1) {
      gmt += gmtSign + Math.abs(gmtFigure);
    }
    return gmt;
  }


digits_count(n) {
    var count = 0;
    n = Math.abs(n);
    if (n >= 1) ++count;
    while (n / 10 >= 1) {
      n /= 10;
      ++count;
    }
    return count;
  }
Source by stackblitz.com #
 
PREVIOUS NEXT
Tagged: #timezone #offset #timezone #javascript
ADD COMMENT
Topic
Name
8+8 =