“JavaScript Convertir UTC a la hora local” Código de respuesta

UTC a la hora local JavaScript

var UTCDate = '6/29/2011 4:52:48 PM';
var localDate = new Date(UTCDate + ' UTC');
MunchDuster

JavaScript Convertir UTC a la hora local

var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
VasteMonde

JS UTC a la zona horaria local

// This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);

console.log(d);                        // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
console.log(d.toLocaleString());       // -> Sat Feb 28 23:45:26 2004
console.log(d.toLocaleDateString());   // -> 02/28/2004
console.log(d.toLocaleTimeString());   // -> 23:45:26
 Run code snippet
Lonely Llama

Respuestas similares a “JavaScript Convertir UTC a la hora local”

Preguntas similares a “JavaScript Convertir UTC a la hora local”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código