Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. function calcTime(city, offset) {
  2.  
  3. // create Date object for current location
  4. d = new Date();
  5.  
  6. // convert to msec
  7. // add local time zone offset
  8. // get UTC time in msec
  9. utc = d.getTime() + (d.getTimezoneOffset() * 60000);
  10.  
  11. // create new Date object for different city
  12. // using supplied offset
  13. nd = new Date(utc + (3600000*offset));
  14.  
  15. // return time as a string
  16. return "The local time in " + city + " is " + nd.toLocaleString();
  17.  
  18. }
  19.  
  20. // get Bombay time
  21. alert(calcTime('Bombay', '+5.5'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement