IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Definition format de date avec mktime


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Homme Profil pro
    Consultant E-Business
    Inscrit en
    Août 2010
    Messages
    216
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant E-Business

    Informations forums :
    Inscription : Août 2010
    Messages : 216
    Points : 96
    Points
    96
    Par défaut Definition format de date avec mktime
    Bonjour à tous,

    Je voudrais définir un format d'affichage de date en mktime.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mktime(0,0,0,$nbrTodayMonth,$afficheJour,$nbrTodayYear)
    Actuellement $afficheJour s'affiche au format 1,2,3 ... alors que je voudrais 01,02,03 ...

    Comment faire pour définir ce format de date ?

    Merci beaucoup par avance,

    Aurélien

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    mktime() produit un timestamp unix, c'est avec date() que tu peux formater ta date.

  3. #3
    Expert éminent sénior

    Homme Profil pro
    Développeur Web
    Inscrit en
    Septembre 2010
    Messages
    5 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

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

    Informations forums :
    Inscription : Septembre 2010
    Messages : 5 389
    Points : 10 422
    Points
    10 422
    Par défaut
    Tu peux nous donner un exemple complet d'où tu pars et de ce que tu veux au final ?

    EDIT j'avais pas vu la réponse de sabotage mais ça va dans le même sens.

  4. #4
    Membre régulier
    Homme Profil pro
    Consultant E-Business
    Inscrit en
    Août 2010
    Messages
    216
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant E-Business

    Informations forums :
    Inscription : Août 2010
    Messages : 216
    Points : 96
    Points
    96
    Par défaut
    Merci pour vos réponses.

    J'ai bricolé et j'ai trouvé une solution (je ne sais pas si c'est la meilleure).

    Si ça intéresse quelqu'un voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    if ($afficheJour == "1" ) { $afficheJourFormat = "01"; 	}
    		if ($afficheJour == "2" ) { $afficheJourFormat = "02"; 	}
    		if ($afficheJour == "3" ) { $afficheJourFormat = "03";	}
    		if ($afficheJour == "4" ) { $afficheJourFormat = "04"; 	}
    		if ($afficheJour == "5" ) { $afficheJourFormat = "05"; 	}
    		if ($afficheJour == "6" ) { $afficheJourFormat = "06";	}
    		if ($afficheJour == "7" ) { $afficheJourFormat = "07"; 	}
    		if ($afficheJour == "8" ) { $afficheJourFormat = "08"; 	}
    		if ($afficheJour == "9" ) { $afficheJourFormat = "09"; 	}		
    		if ($afficheJour == "10" ) { $afficheJourFormat = "10"; 	}
    		if ($afficheJour == "11" ) { $afficheJourFormat = "11"; 	}
    		if ($afficheJour == "12" ) { $afficheJourFormat = "12";	}
    		if ($afficheJour == "13" ) { $afficheJourFormat = "13"; 	}
    		if ($afficheJour == "14" ) { $afficheJourFormat = "14"; 	}
    		if ($afficheJour == "15" ) { $afficheJourFormat = "15";	}
    		if ($afficheJour == "16" ) { $afficheJourFormat = "16"; 	}
    		if ($afficheJour == "17" ) { $afficheJourFormat = "17"; 	}
    		if ($afficheJour == "18" ) { $afficheJourFormat = "18"; 	}
    		if ($afficheJour == "19" ) { $afficheJourFormat = "19"; 	}
    		if ($afficheJour == "20" ) { $afficheJourFormat = "20"; 	}
    		if ($afficheJour == "21" ) { $afficheJourFormat = "21";	}
    		if ($afficheJour == "22" ) { $afficheJourFormat = "22"; 	}
    		if ($afficheJour == "23" ) { $afficheJourFormat = "23"; 	}
    		if ($afficheJour == "24" ) { $afficheJourFormat = "24";	}
    		if ($afficheJour == "25" ) { $afficheJourFormat = "25"; 	}
    		if ($afficheJour == "26" ) { $afficheJourFormat = "26"; 	}
    		if ($afficheJour == "27" ) { $afficheJourFormat = "27"; 	}
    		if ($afficheJour == "28" ) { $afficheJourFormat = "28"; 	}
    		if ($afficheJour == "29" ) { $afficheJourFormat = "29";	}
    		if ($afficheJour == "30" ) { $afficheJourFormat = "30"; 	}
    		if ($afficheJour == "31" ) { $afficheJourFormat = "31"; 	}
    Aurélien

  5. #5
    Expert éminent
    Avatar de Séb.
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    5 228
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 228
    Points : 8 487
    Points
    8 487
    Billets dans le blog
    17
    Par défaut
    A simplifier avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $afficheJourFormat = sprintf('%02d', $afficheJour) ;
    Ou :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if ( strlen($afficheJour) == 1 ) {
        $afficheJourFormat = '0' . $afficheJour ;
    } else {
        $afficheJourFormat = $afficheJour ;
    }
    Ceci dit je pense que tu pourras obtenir le bon formatage plus simplement avec date( ).

  6. #6
    Membre régulier
    Homme Profil pro
    Consultant E-Business
    Inscrit en
    Août 2010
    Messages
    216
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant E-Business

    Informations forums :
    Inscription : Août 2010
    Messages : 216
    Points : 96
    Points
    96
    Par défaut
    Merci beaucoup !!!

    Aurélien

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. probleme de date avec mktime et gmtime
    Par firejocker dans le forum MFC
    Réponses: 2
    Dernier message: 12/04/2010, 13h57
  2. Réponses: 23
    Dernier message: 26/09/2007, 12h35
  3. Formater une date avec 23:59:59
    Par Caro dans le forum Firebird
    Réponses: 4
    Dernier message: 29/08/2007, 13h06
  4. Format des date avec webviewer
    Par zambizi dans le forum BIRT
    Réponses: 2
    Dernier message: 30/06/2007, 17h01
  5. [VB]Format de date avec excell
    Par Empty_body dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 16/02/2006, 14h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo