note 79646 deleted from function.date by derick

From: Date: Sun, 09 Dec 2007 13:36:31 +0000
Subject: note 79646 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-132995@lists.php.net to get a copy of this message
Note Submitter: Sir_bline ---- i have seen the note from Eren - erenezgu and i was looking for a function to display personalized current hour and date too my function get able to drop a gmt value into our db. with this member value i can know about his real born date or rebuild the "is online or not" values displayed to other members. we can build other linked functions too if we want, maybe not really short but usefull // we need two values => // $time get able to separate hours from date // $from gmt is a '+i' or '-i' value function current_date_time($time,$from_gmt) { global $curent_hour, $curent_date; // define the vars => 't' is good for who don't want to // care about the max days for the // current month - usefull for leaped years! $t = date(t); $old_year = date(Y); $old_month = date(n); $old_day = date(j); $old_hour = date(G); $minut = date(i); $seconds = date(s); $hour = ceil($old_hour+$from_gmt); // search if gmt is negative or positive // and set new day if it change the value // and rock and roll to the year if($hour < '0') { $hour = ceil(24+$hour); $day = ceil($old_day-'1'); } elseif($hour > '23') { $dif = ceil($hour-24); $hour = ceil(0+$dif); $day = ceil($old_day+'1'); } else { $day = $old_day; } if($day > $t) { $day = '01'; $month = ceil($month+1); } elseif($day == '0') { $day = $t; $month = ceil($month-1); } else { $month = $old_month; } if($month > '12') { $year = ceil($old_year-1); $month = '01'; } elseif($month == '0') { $month = '12'; $year = ceil($old_year-1); } else { $year = $old_year; } // i have defined vars without the '0' // because ceil destroy it so add it // if we need it... if($hour < '10') { $hour = '0'.$hour; } if($month < '10') { $month = '0'.$month; } if($day < '10') { $day = '0'.$day; } if($time == 'hours') { $curent_hour = "$hour-$minut-$seconds"; } elseif($time == 'date') { $curent_date = "$year-$month-$day"; } } // after that i use a split to manage it // for exemple: if(isset($_POST['fuseau'])) { current_date_time('date',$_POST['fuseau']); list($an,$mois,$jour) = split('\-',$curent_date); current_date_time('hours',$_POST['fuseau']); list($heurre,$minutes,$secondes) = split('\-',$curent_hour); echo'si le fuseau horraire était GMT', $_POST['fuseau'] ,'' .'<br />nous serions le: ', $jour ,'/', $mois ,'/', $an ,'' .'<br />et il serait: ', $heurre ,'h:', $minutes ,'';

« previous php.notes (#132995) next »