Created
March 9, 2012 11:48
-
-
Save BenjaminGuV/2006220 to your computer and use it in GitHub Desktop.
calcular la zona horaria de una ciudad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// funcion para calcular la hora local en una ciudad dada la diferencia horaria. | |
function calcTime(city, offset) { | |
// creamos el objeto Date (la selecciona de la máquina cliente) | |
d = new Date(); | |
// lo convierte a milisegundos | |
// añade la dirferencia horaria | |
// recupera la hora en formato UTC | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
// crea un nuevo objeto Date usando la diferencia dada. | |
nd = new Date(utc + (3600000*offset)); | |
// devuelve la hora como string. | |
return "La hora actual en " + city + " es: " + nd.toLocaleString(); | |
} | |
//Bombay | |
alert(calcTime('Bombay', '+5.5')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment