Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js get current timezone offset

console.log(new Date().getTimezoneOffset()/-60) // offset in hours
Comment

get offset from timezone javascript

// Following function can be used to return the UTC offset given a timezone:

const getTimezoneOffset = (timeZone, date = new Date()) => {
  const tz = date.toLocaleString("en", {timeZone, timeStyle: "long"}).split(" ").slice(-1)[0];
  const dateString = date.toString();
  const offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);
  
  // return UTC offset in millis
  return offset;
}


//It can be used like:

const offset = getTimezoneOffset("Europe/London");
console.log(offset);
// expected output => 3600000
Comment

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;
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: React import image with url 
Javascript :: js conditional object key 
Javascript :: convert string to number javascript 
Javascript :: jquery on click remove parent div 
Javascript :: useScreens() react native 
Javascript :: react-phone-number-input retur message in react hook form 
Javascript :: delete a property of html by js 
Javascript :: ajax form picture upload 
Javascript :: moment js difference between two dates 
Javascript :: npm stylelint 
Javascript :: jquery noconflict 
Javascript :: shuffle array javascript 
Javascript :: create array javascript 
Javascript :: math.factorial 
Javascript :: angularjs accordion access toggle 
Javascript :: javascript get all child elements 
Javascript :: javascript get sum array values 
Javascript :: random numbers javascript 
Javascript :: how to call a function with arguments on event listener javascript 
Javascript :: install swagger jsdoc 
Javascript :: angular loop 
Javascript :: html form post json example 
Javascript :: linker call rect native 
Javascript :: i18n react get current language 
Javascript :: fetch data in next js 
Javascript :: createelement with id javascript 
Javascript :: moment js check if date is greater than 
Javascript :: javascript if a variable is undefined 
Javascript :: json-server npm 
Javascript :: simple javascript code 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =