“JavaScript convertit UTC en heure locale” Réponses codées

UTC à l'heure locale javascript

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

JavaScript convertit UTC en heure locale

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 à la fuseau horaire locale

// 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

Réponses similaires à “JavaScript convertit UTC en heure locale”

Questions similaires à “JavaScript convertit UTC en heure locale”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code