Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript
JavaScript Forum programmation JavaScript. Lire : Cours JavaScript, FAQ JavaScript, Toutes les FAQ JavaScript et Sources JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 25/03/2011, 17h14   #1
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 54
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : mars 2011
Messages : 54
Points : 1
Points : 1
Par défaut detecter automatiquement le Daylight saving time(dst)

Bonjour,

je developpe un site intranet .sur mon site ja affiché l'heure(evolue pas statique) de plusieurs pays(france,uk,boston,london...).pour faire ça j'ai utilisé un script javascript dont le code
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 				<script type="text/javascript">
	var listHtmlElem = [];
	//listHtmlElem.push([$(DIV_ID),GMT]);
	listHtmlElem.push([$('LD'),+1]);
	listHtmlElem.push([$('Bos-Mer'),-4]);
	listHtmlElem.push([$('Dallas'),-5]);
	listHtmlElem.push([$('Loc'),+2]);
	listHtmlElem.push([$('Bangalore'),+7]);
 
	 function $(id){
	return document.getElementById(id);
		}
 
	 function displayTime(HtmlElem,gmt){
	var date = new Date();
	var utc = gmt;
	var Hour;
 
	utc *= 60; // minutes
	utc += date.getTimezoneOffset(); // correction local -> gmt
	utc *= 60000; // millisecondes
	Hour=new Date(date.getTime() + utc).toUTCString().replace('UTC','').split(' ');
	HtmlElem.innerHTML = Hour[4];
		}
 
	 function updateTime(){
 
	for(var i in listHtmlElem)
 
		displayTime(listHtmlElem[i][0],listHtmlElem[i][1]);
		}
	setInterval(updateTime,1000);
 
</script>
je veux qu'on detecte automatiquement le Daylight saving time (dst) (ajout ou soustraction d'une heure ou plus dans certains pays).
peut on changer le code pour faire ça ?
merci d'avance.
developer5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2011, 13h33   #2
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 54
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : mars 2011
Messages : 54
Points : 1
Points : 1
s'il vous plait si qq a une ideé comment tenir compte du le Daylight saving time utilisant javascript peut -il- m'aider .
merci
developer5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/03/2011, 21h54   #3
Membre expérimenté
 
Avatar de nadox
 
Homme
Développeur
Inscription : février 2010
Messages : 360
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Calvados (Basse Normandie)

Informations professionnelles :
Activité : Développeur
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2010
Messages : 360
Points : 545
Points : 545
Bonsoir,

http://www.google.com/search?q=detec...ith+javascript

1er résultat : http://www.michaelapproved.com/artic...me-dst-detect/
nadox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 16h21   #4
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 54
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : mars 2011
Messages : 54
Points : 1
Points : 1
Bonjour,
je vous remerci pour ton aide.j'ai ajouter les deux fonctions dans un meme script mais malheureusement ça marche pas?
developer5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 18h27   #5
Membre expérimenté
 
Avatar de nadox
 
Homme
Développeur
Inscription : février 2010
Messages : 360
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Calvados (Basse Normandie)

Informations professionnelles :
Activité : Développeur
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2010
Messages : 360
Points : 545
Points : 545
Quelle est la question ? Ça marche pas ? Je ne peux pas deviner le code que tu as sous les yeux...
nadox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 19h02   #6
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 54
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : mars 2011
Messages : 54
Points : 1
Points : 1
desolé mais je parle des fonctios situé dans le lien que vous m'avez envoyé
voici le code
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
<script>
 
function TimezoneDetect(){ 
    var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear()); 
    var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt 
    var intMonth; 
    var intHoursUtc; 
    var intHours; 
    var intDaysMultiplyBy; 
 
    //go through each month to find the lowest offset to account for DST 
    for (intMonth=0;intMonth < 12;intMonth++){ 
        //go to the next month 
        dtDate.setUTCMonth(dtDate.getUTCMonth() + 1); 
 
        //To ignore daylight saving time look for the lowest offset. 
        //Since, during DST, the clock moves forward, it'll be a bigger number. 
        if (intOffset > (dtDate.getTimezoneOffset() * (-1))){ 
            intOffset = (dtDate.getTimezoneOffset() * (-1)); 
        } 
    } 
 
    return intOffset; 
}
 
//Find start and end of DST 
function DstDetect(){ 
    var dtDstDetect = new Date(); 
    var dtDstStart = ''; 
    var dtDstEnd = ''; 
    var dtDstStartHold = ''; //Temp date hold 
    var intYearDayCount = 732; //366 (include leap year) * 2 (for two years) 
    var intHourOfYear = 1; 
    var intDayOfYear; 
    var intOffset = TimezoneDetect(); //Custom function. Make sure you include it. 
 
    //Start from a year ago to make sure we include any previously starting DST 
    dtDstDetect = new Date() 
    dtDstDetect.setUTCFullYear(dtDstDetect.getUTCFullYear() - 1); 
    dtDstDetect.setUTCHours(0,0,0,0); 
 
    //Going hour by hour through the year will detect DST with shorter code but that could result in 8760 
    //FOR loops and several seconds of script execution time. Longer code narrows this down a little. 
    //Go one day at a time and find out approx time of DST and if there even is DST on this computer. 
    //Also need to make sure we catch the most current start and end cycle. 
    for(intDayOfYear = 1; intDayOfYear <= intYearDayCount; intDayOfYear++){ 
        dtDstDetect.setUTCDate(dtDstDetect.getUTCDate() + 1); 
 
        if ((dtDstDetect.getTimezoneOffset() * (-1)) != intOffset && dtDstStartHold == ''){ 
            dtDstStartHold = new Date(dtDstDetect); 
        } 
        if ((dtDstDetect.getTimezoneOffset() * (-1)) == intOffset && dtDstStartHold != ''){ 
            dtDstStart = new Date(dtDstStartHold); 
            dtDstEnd = new Date(dtDstDetect); 
            dtDstStartHold = ''; 
 
            //DST is being used in this timezone. Narrow the time down to the exact hour the change happens 
            //Remove 48 hours (a few extra to be on safe side) from the start/end date and find the exact change point 
            //Go hour by hour until a change in the timezone offset is detected. 
            dtDstStart.setUTCHours(dtDstStart.getUTCHours() - 48); 
            dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() - 48); 
 
            //First find when DST starts 
            for(intHourOfYear=1; intHourOfYear <= 48; intHourOfYear++){ 
                dtDstStart.setUTCHours(dtDstStart.getUTCHours() + 1); 
 
                //If we found it then exit the loop. dtDstStart will have the correct value left in it. 
                if ((dtDstStart.getTimezoneOffset() * (-1)) != intOffset){ 
                    break; 
                } 
            } 
 
            //Now find out when DST ends 
            for(intHourOfYear=1; intHourOfYear <= 48; intHourOfYear++){ 
                dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() + 1); 
 
                //If we found it then exit the loop. dtDstEnd will have the correct value left in it. 
                if ((dtDstEnd.getTimezoneOffset() * (-1)) != (intOffset + 60)){ 
                    break; 
                } 
            } 
 
            //Check if DST is currently on for this time frame. If it is then return these values. 
            //If not then keep going. The function will either return the last values collected 
            //or another value that is currently in effect 
            if ((new Date()).getTime() >= dtDstStart.getTime() && (new Date()).getTime() <= dtDstEnd.getTime()){ 
                return new Array(dtDstStart,dtDstEnd); 
            } 
 
        } 
    } 
    return new Array(dtDstStart,dtDstEnd); 
}
</script>
developer5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 19h19   #7
Membre expérimenté
 
Avatar de nadox
 
Homme
Développeur
Inscription : février 2010
Messages : 360
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Calvados (Basse Normandie)

Informations professionnelles :
Activité : Développeur
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2010
Messages : 360
Points : 545
Points : 545
A quel endroit tu utilise le code ? Comment ? Il ne suffit pas de copier/coller le script, il faut aussi l'utiliser (dans ton code) !
nadox est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 20h52   #8
Invité de passage
 
Homme
Inscription : mars 2011
Messages : 54
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : mars 2011
Messages : 54
Points : 1
Points : 1
je l'ai mis dans le body
developer5 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2011, 21h12   #9
Membre expérimenté
 
Avatar de nadox
 
Homme
Développeur
Inscription : février 2010
Messages : 360
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Calvados (Basse Normandie)

Informations professionnelles :
Activité : Développeur
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : février 2010
Messages : 360
Points : 545
Points : 545
Tu as mis quoi dans le body ? Juste le code des fonctions ? Ben il ne va pas faire ce que tu veux comme par magie !

Il faut modifier ton premier code pour qu'il utilise les fonctions. Si tu ne sais pas faire ça, il faut peut-être commencer par apprendre javascript !
nadox est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h02.


 
 
 
 
Partenaires

Hébergement Web