Vous n'êtes pas identifié.

Annonces

Les pages de ce Forum sont exploitables par les Navigateurs Mozilla, Fire Fox, Opera, Safari, Konqueror, Netscape, MSIE.
  • Index
  •  » Le Java
  •  » Automatiser un affichage selon la date

#1 [↑] [↓]04/12/2009 11:02:34

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Automatiser un affichage selon la date

Voici un exemple d'utilisation des différentes méthodes de la propriété Date() :

Code :

<script type="text/javascript">
	<!--
		theDate = new Date(); // récupère la date système du PC et la transfère dans l'objet theDate
		var mm = theDate.getMonth(); // le mois de 0 à 11
		var dd = theDate.getDate(); // le jour de 1 à 30 ou 31 sauf février (28 ou 29)
		var yy = theDate.getFullYear(); // l'année sur 4 chiffres [getYear() ne doit plus être utilisé]
		if (mm == 11 && (dd == 24 || dd == 25))
			document.write('<center><hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b><font color="red">Joyeux</font>&nbsp;<font color="blue">Noël</font></b></big></big></center>');
		if (mm == 0 && dd <8)
			document.write('<center><hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b><font color="red">Meilleurs</font>&nbsp;<font color="blue">Vœux</font>&nbsp;<font color="gray">pour</font>&nbsp;<font color="green">'+yy+'</font></b></big></big></center>');
	// -->
</script>

Il est utilisé (sous une forme légèrement différente) par le Script du Forum Cigiema.
Cela provoque les affichages suivants (dans le panneau "Annonces" sous le Header) :

- Les 24 et 25 décembre


http://www.cigiema.fr/images/guirlande_noel.gif
Joyeux Noël

- Du 1er au 7 janvier inclus


http://www.cigiema.fr/images/guirlande_noel.gif
Meilleurs Vœux pour YYYY

YYYY = Le nombre correspondant à l'année (exemple : 2010).

wink
Alain AKA Arma

PS : la méthode getDay() retourne un chiffre de 0 à 6 (du dimanche au samedi).

<edit Khan Gourou>     http://forum.cigiema.fr/img/grande_classe.gif     </edit>

<edit Smeagold> C'est un truc de fainéant ! Comme ça, Crazy ne s'embête plus... </edit>

<edit Le Lutin>     http://forum.cigiema.fr/img/trop_bien_dit.gif     </edit>

<edit Zibou>     http://forum.cigiema.fr/img/pas-faux.gif     </edit>


Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 

#2 [↑] [↓]04/12/2009 11:42:03

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Re: Automatiser un affichage selon la date

On peut aussi le faire sur un serveur Web [avec PHP et XHTML]) :

Code :

<?php
if (date("m") == '12' && (date("d") == '24' || date("d") == '25'))
{
	// Joyeux Noël
?>
<center>
	<font size="3">
		<img src="http://www.cigiema.fr/images/guirlande_noel.gif" alt="Guirlande" /><br />
		<b><font color="red">Joyeux</font>&nbsp;<font color="blue">Noël</font>&nbsp;!</b>
	</font>
</center>
<?php
}
elseif (date("m") == '01' && (int)date("d") <8)
{
	// Meilleurs Vœux...
?>
<center>
	<font size="3">
		<img src="http://www.cigiema.fr/images/guirlande_noel.gif" alt="Guirlande" /><br />
		<b><font color="red">Meilleurs</font>&nbsp;<font color="blue">Vœux</font>&nbsp;
		<font color="gray">pour</font>&nbsp;<font color="green"><?php echo date("Y"); ?></font>.</b>
	</font>
</center>
<?php
}
?>

Ceci est une partie allégée d'une portion du Script /include/user/message_resume_index.php (Annuaire Cigiema).
wink
Alain AKA Arma

[Vous devez être identifié pour voir le texte caché.]

Dernière modification par Crazy (06/12/2009 14:52:48)



Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 

#3 [↑] [↓]09/12/2009 09:41:00

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Re: Automatiser un affichage selon la date

Sur l'Annuaire Cigiema, j'ai aussi adopté la gestion de la date par JavaScript (avec un peu de PHP).
En effet, il vaut mieux utiliser l'heure locale du PC de l'Internaute que celle du Serveur !

Voici le code (qui tient compte de la langue par défaut du Navigateur Client) :

Code :

<script type="text/javascript">
	<!--
		var mm = parseInt((new Date()).getMonth());
		var dd = parseInt((new Date()).getDate());
		if (mm == 11 && (dd == 24 || dd == 25))
		{
			document.write('<hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b>');
<?php
	if ($lang == 'fr') echo 'document.write(\'<font color="red">Joyeux</font>&nbsp;<font color="blue">Noël</font>\');';
	else echo 'document.write(\'<font color="red">Merry</font>&nbsp;<font color="blue">Christmas</font>\');';
?>
			document.write('</b></big></big>');
		}
		if (mm == 0 && dd <8)
		{
			document.write('<hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b>');
<?php
	if ($lang == 'fr') echo 'document.write(\'<font color="red">Meilleurs</font>&nbsp;<font color="blue">Vœux</font>&nbsp;<font color="gray">pour</font>\');';
	else echo 'document.write(\'<font color="red">Best</font>&nbsp;<font color="blue">Wishes</font>&nbsp;<font color="gray">for</font>\');';
?>
			document.write('&nbsp;<font color="green">'+parseInt((new Date()).getFullYear())+'</font></b></big></big>');
		}
	// -->
</script>

wink
Alain AKA Arma

PS : La détection de la langue (en full PHP)...

Code :

<?php
// Created by Crazy (c)2008-2009
// ------------------------------------ INFOS COOKIE ---------------------------------------
$cookie_time = time() + (3600 * 24 * 365); // Validité du cookie : 1 an
$cookie_path = ($racine_annuaire == '') ? '/' : $racine_annuaire;
$cookie_domain = $_SERVER['SERVER_NAME'];
$cookie_secure = FALSE;
// ------------------------------------------------------------------------------------------------
// Si pas de Cookie et que PHP connait la langue du Client alors on la force sans vergogne
if (!isset($_COOKIE["cigiema_lang"]))
{
	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
	{
		if (stristr($_SERVER['HTTP_ACCEPT_LANGUAGE'],'fr')) $lang = 'fr';
		else $lang = 'en';
		setcookie('cigiema_lang', $lang, $cookie_time, $cookie_path, $cookie_domain, $cookie_secure); // Cookie pour la prochaine page
	}
}
else $lang = $_COOKIE["cigiema_lang"]; // l'utilisateur a déjà choisi sa langue... Alors, on la teste dans le cookie pour qu'il ait toujours la même config (il peut la changer)
?>

tongue


Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 

#4 [↑] [↓]09/12/2009 10:36:58

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Re: Automatiser un affichage selon la date

Pour afficher automatiquement la date anniversaire d'un site
(cela paraît blaireau mais pour un site eCommerce, ça peut servir(*))...
Bah oui, pourquoi pas ? On a quand même le droit d'être fainéant et de laisser l'informatique gérer...

La méthode est la suivante :
1) Récupérer la date de création sur le WhoIs (http://www.whois.org) ;
2) La comparer à la date du Serveur (oui, là, il convient d'utiliser celle du Serveur) ;
3) Si MATCH (Date_WhoIs == Date_Serveur) ==> Afficher un message(**).

Facile, non ?
Mais il faudra le faire en PHP... whistling ...
wink
Alain AKA Arma

(*) Pour donner un code de PROMO (généré aléatoirement par le Serveur et enregistré en BDD, tant qu'à faire), par exemple.

(**) On peut aussi afficher l'âge du site en faisant une soustraction sur l'année (Date_Serveur - Date_WhoIs)...
Au jour dit ou pendant tout le mois (tester le jour exact [JJ/MM] ou uniquement le mois...
Pour une telle chose, le RegExp (en PHP) peut éventuellement servir !
bleh

PS : Au travail ! shout


Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 

#5 [↑] [↓]27/12/2009 09:03:41

rgo74
Ami des Alpages
rgo74
Lieu: Toute la Haute Savoie
Date d'inscription: 17/05/2006
Messages: 911
Site web

Re: Automatiser un affichage selon la date

Nickel wink


Hors ligne

 

#6 [↑] [↓]28/01/2010 17:50:20

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Re: Automatiser un affichage selon la date

Eh oui, ce n'est pas trop nul comme truc zarbi...
On peut même faire dans ce genre là :

Code :

<script type="text/javascript">
	<!--
	var hh = parseInt((new Date()).getHours());
	if (hh > 5 && hh <18) // de 06:00 à 17:59 (journée)
		var bgsound = new Array('','http://crazy.cigiema.fr/musique/zik.mid','http://crazy.cigiema.fr/musique/prelude.mid');
	else // de 18:00 à 05:59 (soirée et nuit) et en streaming automatique...
	{
		var bgsound = new Array('','http://crazy.cigiema.fr/musique/goeland.wma','http://crazy.cigiema.fr/musique/prelude.wma','http://crazy.cigiema.fr/musique/rapetout.wma');
		if (hh <6) // ajout de ziks de 00:00 à 05:59 (nuit) toujours en streaming (quand cela fonctionne)...
			bgsound.push('http://crazy.cigiema.fr/musique/quequette.wma','http://crazy.cigiema.fr/musique/chier.wma','http://crazy.cigiema.fr/musique/tripote-bi*te (D'Amarrage ?).wma','http://crazy.cigiema.fr/musique/lifting.mp3');
	}
	alea = Math.floor(Math.random() * bgsound.length);
	if (alea > 3 && !confirm("ATTENTION !\n\nL\'élément Audio présélectionné\nest réservé à un auditoire averti.\n\nSi vous voulez l\'entendre, cliquez sur [ OK ],\nsi vous ne savez pas, cliquez sur [ Annuler ].")) alea = 0; // ou 1, SSV...
	if (alea) document.write('<object type="application/x-mplayer2"><param name="src" value="'+bgsound[alea]+'"><param name="autoplay" value="true"><param name="loop" value="false"><param name="volume" value="25"><param name="width" value="0"><param name="height" value="0"><\/object>'); 
	// -->
</script>

Ce n'est pas de l'affichage mais une sélection musicale... whistling ...
wink
Alain AKA Arma

PS : Voir --> http://forum.cigiema.fr/p21544-18-10-2009.html#p21544 ou http://forum.cigiema.fr/t2241-Musique-s … e-W3C.html


Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 

#7 [↑] [↓]25/02/2010 17:05:38

Crazy
Super Admin azimuté
Crazy
Lieu: Côte d'Azur - FRANCE
Date d'inscription: 10/04/2006
Messages: 5462
Site web

Re: Automatiser un affichage selon la date

Crazy a écrit :

Il est utilisé (sous une forme légèrement différente) par le Script du Forum Cigiema.

Voici donc le code JavaScript utilisé ICI :

Code :

<script type="text/javascript">
<!--
	var mm = parseInt((new Date()).getMonth());
	var dd = parseInt((new Date()).getDate());
	if (mm == 11 && (dd == 24 || dd == 25))
		document.write('<hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b><font color="red">Joyeux</font>&nbsp;<font color="blue">Noël</font></b></big></big>');
	if (mm == 0 && dd <8)
		document.write('<hr><img src="http://www.cigiema.fr/images/guirlande_noel.gif"><br><big><big><b><font color="red">Meilleurs</font>&nbsp;<font color="blue">Vœux</font>&nbsp;<font color="gray">pour</font>&nbsp;<font color="green">'+parseInt((new Date()).getFullYear())+'</font></b></big></big>');
// -->
</script>

Et attention aux parenthèses dans le dernier document.write !
wink
Alain AKA Arma


Je suis Bon (avec un grand C) et Immortel... Jusqu'à preuve du contraire !
http://crazy.cigiema.fr/chocoku/ - http://crazy.cigiema.fr/sorcier_glouton/ - http://crazy.cigiema.fr/tiger-osmose/
http://crazy.cigiema.fr/msnbetter_thangoogle/ - http://crazy.cigiema.fr/black-hattitude/

I remember and I feel free! - I am the Killer of the Lambs!

Hors ligne

 
  • Index
  •  » Le Java
  •  » Automatiser un affichage selon la date

Pied de page des forums

Powered by PunBB modified
© Copyright 2002–2005, Rickard Andersson
© Interface & Functional Add-ons Copyright 2006-2007, by Crazy


RSS Forum CIGIEMA

© 2006-2010 / A. G.
CiGi€M@®, 1997-2010
IDDN Reproduction totale ou partielle strictement interdite
Contact :
/