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 :: javascript round to 1 decimal 
Javascript :: jquery offsetheight 
Javascript :: first and last char vowel reg exp same char 
Javascript :: jquery focus 
Javascript :: (node:5547) UnhandledPromiseRejectionWarning: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" 
Javascript :: jquery reload iframe 
Javascript :: array.find is not a function 
Javascript :: copy to clipboard jquery javascript 
Javascript :: jquery find previous element with class 
Javascript :: column.footer jquery 
Javascript :: puppeteer get attribute 
Javascript :: loop array in javascript 
Javascript :: gsap js link 
Javascript :: javascript get now date yyyy-mm-dd 
Javascript :: how to disable back js 
Javascript :: convert elements to array javascript 
Javascript :: jquery div element find and remove 
Javascript :: multiple line string in jquery 
Javascript :: how to put text in the center react native 
Javascript :: comment jsx code 
Javascript :: $(this).text() in jquery return white space 
Javascript :: how to append values to dropdown using jquery 
Javascript :: javascript check if a number is even or odd 
Javascript :: jquery today date 
Javascript :: how to hide button in react 
Javascript :: smooth link to anchor js 
Javascript :: windows how to set process.env variables 
Javascript :: js markdown to html 
Javascript :: javascript string starts with 
Javascript :: create an array of numbers 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =