views:

18

answers:

1

Hi,

i have a problem, and maybe someone can help me, i will explain...

  1. i have the in javascript "var date= new date();" and its give me the local time (browser time) but i want force this data/time for a especific local... for example... Spain. i want everytime that someone enter in the page (from others country) the date need be the spanish hour.

i found some soluction but the problem is the summer time and winter time... we have offset variations because some time is +1 hours and others is +2....

someone can help me in one soluction?

thanks [email protected]

A: 

Take a look at this article: http://articles.techrepublic.com.com/5100-10878_11-6016329.html

Lifted straight out from that:

 function calcTime(city, offset) {

// create Date object for current location
d = new Date();

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

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

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

 }

Call it like: alert(calcTime('Bombay', '+5.5')); // get Bombay time

You may need to add a bit of logic to take into account daylight saving time.

David Neale
thanks, but i already checked this code, but my problem is in this case u are saying that the diference is 5hours and half... everytime, but sometime is less or more (i don't know exacly for bombay :)how can i do this? hard code logic? for 2010? and then 2011.. bc maybe every diferent year the date that change the hour is diferent.thanks :d
Joao
David Neale