0

I'm setting up a code for a timer and I need to have the currentTimein the correct timezone. I have therefore to different codes. One code with the correct currentTime and the other codethat is only doing localtime. I am trying to add the code that has the correct timezonein to the other code but I can't get it work.

Here is the code with timezone:

var $ = window.jQuery;

var setTime = function(){
  var date = moment().tz("Europe/Paris");
  
  var day = date.day();
      
  console.log('date', date);
  console.log('day', day);
  
  var time = date.format("h:mm A");
  
  console.log(time, time);
  
  $('#current-time').html("Current time: " + time + " ");
};

setTime();

And here is the code wit local time.

var current = new Date();
var day = current.getDay();
var currentTime = (currentTime) = (current.getHours() * 60) + current.getMinutes();
var remainTime = 0;
var closeTime = (openTime[day].close *60);
var openTime = (openTime[day].open *60);
Jake
  • 21
  • 3

1 Answers1

0

You can always use the Date() function and calculate the offset of time.

For example:

function calcTime(city, offset) {
    // create Date object for current location
    var d = new Date();

    // convert to msec
    // subtract local time zone offset
    // get UTC time in msec
    var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    // create new Date object for different city
    // using supplied offset
    var nd = new Date(utc + (3600000*offset));

    // return time as a string
    return "The local time for the city "+ city +" is "+ nd.toLocaleString();
}

alert(calcTime('Paris', '+2'));

Retrieved from here

TeigeC
  • 86
  • 8