2

Well I need to know what hours will be 9am in user time compared with my timezone.

like:

I'm from Brazil 9 am GMT -0300

i.e: some user from 'Cairo' access my website then I need to know when will be 9 am in his time compared with my time 'Cairo' gmt is +0200.

Is there a way to do it with Javascript?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156

2 Answers2

3

You are probably looking for getTimezoneOffset() method (see http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp):

var d = new Date()
var n = d.getTimezoneOffset();

n will be the timezone difference between UTC and Local Time in minutes.

More comprehensive guide here: http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/.

EDIT: Oh, I forgot about the future time part. In that case, it should be enough to create custom date instance using one of the extended constructors:

var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);

It can be used to determine the timezone difference at that time. You can easily determine the offset o at some time, and the final offset at the specified time is either o, o + 60 or o - 60, which can be easily checked with getTimezoneOffset() on the Date object created with the extended constructor.

In the worst-case scenario, you might have to do 2-3 calculation steps to determine your final result.

petr
  • 179
  • 9
-1

Checkout: javascript timezone converter, there's an already open discussion there about your inquired topic.

Community
  • 1
  • 1
Uri May
  • 365
  • 2
  • 7