Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- // get Bombay time
- alert(calcTime('Bombay', '+5.5'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement