Formater l'heure (temps) en php

Résolu
JypX Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   -  
JypX Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Je n'arrive pas à reformater l'heure....
Je récupère l'heure avec ce format : 01:02:23 (base mysql)

<html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
setlocale (LC_TIME, 'fr_FR.utf8','fra');
// echo strftime("%A %d %B %Y %T %H:%M:%S");
echo strftime("%A %e %B %Y", strtotime(20100312));
// Affiche : vendredi 12 mars 2010 C OK!!!
echo "<br />";
echo strftime("%Hh %Mmin %Ss", 010223);
// Aimerai afficher : 01h 02min 23s ou 1h 2min 23s
// Mais affiche : 02h 10min 43s
?>
</body>
</html> 
A voir également:

3 réponses

Alain_42 Messages postés 5361 Date d'inscription   Statut Membre Dernière intervention   894
 
une autre solution:

$heure="01:10:23";
$array_heure=explode(":",$heure);
echo $array_heure[0]."h ".$array_heure[1]."mn ".$array_heure[2]."s";
1
JypX Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   7
 
Merci pour ton aide
0
JypX Messages postés 67 Date d'inscription   Statut Membre Dernière intervention   7
 
Si ça peut aider :
<html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$toto="12:02:50";

echo reformter_duree($toto);

function reformter_duree ($duree) {

	$array=explode(":",$duree); // Envoie les heures, minutes et secondes dans un tableau
	if ($array[0]>0) { $h=intval($array[0])."h "; }  // N'affiche pas les heures si il n'y a pas d'heure
	if ($array[1]>0) { $min=intval($array[1])."min "; }  // N'affiche pas les minutes si il n'y a pas de minute
	elseif ($array[0]>0 AND $array[2]>0) { $min="0min "; } // Affiche 0min si on affiche les heures et les secondes, c'est plus joli
	if ($array[2]>0) { $s=intval($array[2])."s"; }  // N'affiche pas les secondes si il n'y a pas de seconde
	return $h.$min.$s;

}
?>
</body>
</html>  
0