Advertisement
soyuka

date french php

Mar 28th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. function timeDiff($s){
  2.     $m=0;$hr=0;$d=0;$td="à l'instant";
  3.     if($s>59) {
  4.         $m = (int)($s/60);
  5.         $s = $s-($m*60); // sec left over
  6.         $td = "$m min";
  7.     }
  8.     if($m>59){
  9.         $hr = (int)($m/60);
  10.         $m = $m-($hr*60); // min left over
  11.         $td = "$hr h";
  12.         if($m>0) $td .= ", $m min";
  13.     }
  14.     if($hr>23){
  15.         $d = (int)($hr/24);
  16.         $hr = $hr-($d*24); // hr left over
  17.         $td = "$d ".'jour'; if($d>1) $td .= "s";
  18.         if($d<3){
  19.             if($hr>0) $td .= ", $hr h";
  20.         }
  21.     }
  22.     return $td;
  23. }
  24.  
  25. function secAsTime($s) {
  26.     $min = $s/60;
  27.     $heures = $s/3600;
  28.     $jours = $s/(3600*24);
  29.    
  30.     $mois = intval($s/(30*24*3600));
  31.     $phrase = $mois.' mois';
  32.    
  33.     $jours = intval($jours - ($mois*30));
  34.     $phrase .= ($jours != 0) ? ', '.$jours.' jours' : '';
  35.  
  36.     $heures = intval($heures - ($jours * 24) - ($mois*30*24));
  37.     $phrase .= ($heures != 0) ? ', '.$heures.' heures' : '';
  38.  
  39.     $min = intval($min - ($heures*60) - ($jours * 24 * 60) - ($mois*30*24*60));
  40.     $phrase .= ($min != 0) ? ' et '.$min.' min' : '';
  41.  
  42.     return $phrase;
  43. }
  44.  
  45. function timeForMessages($dateTime, $lang = false) {
  46.     $monthFr = array('', 'Jan', 'F&eacute;v', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Ao&ucirc;', 'Sep', 'Oct', 'Nov', 'D&eacute;c');
  47.     $monthDe = array('', 'Jan', 'Feb', 'M&auml;r', 'Avr', 'Ma&iuml;', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez');
  48.  
  49.     $i = date("n", strtotime($dateTime));
  50.    
  51.     switch($lang) {
  52.         case 'fr_FR':
  53.             $month = $monthFr[$i];
  54.         break;
  55.         case 'de_DE':
  56.             $month = $monthDe[$i];
  57.         break;
  58.         case 'en_US':
  59.             $month = date("M ", strtotime($dateTime));
  60.         break;
  61.         default:
  62.             $month = date("M ", strtotime($dateTime));
  63.     }      
  64.    
  65.     $dateTrans = date("j ", strtotime($dateTime));
  66.     $dateTrans .= $month;
  67.     $dateTrans .= date(" G:i", strtotime($dateTime));
  68.    
  69.     return $dateTrans;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement