Here are the sample codes:

  1.     var dt = new Date;
        console.log( dt.getTimezoneOffset() ); // -480
    
  2. The final codes are shown below and you can see the effect here or click the figure on the top right.
      var dt = new Date;
      console.log( dt.getTimezoneOffset() ); // -480
      var dt = new Date;
      dt.setMinutes( dt.getMinutes() + dt.getTimezoneOffset() ); // current time(mins) + time zone shift(mins)
      var dt_hour = 3;
      var dt_min  = 0; 
      function iniTime() { 
        var now = new Date();
          mincr = dt.getMinutes() + dt_min;
          hincr = dt.getHours() + dt_hour;
          console.log( "GMT format: ", now.toLocaleString());
          console.log( "Local time format: ", now);
      }
      iniTime();
    

For more information, please refer to javascript obtaining global time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your email address will not be published. Required fields are marked *

Submit