note 79646 added to function.date
| From: | Sir_bline at osu1 dot php dot net | Date: | Thu, 06 Dec 2007 15:20:46 +0000 |
| Subject: | note 79646 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132892@lists.php.net to get a copy of this message | ||
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 ,'';
----
Server IP: 195.221.21.36
Probable Submitter: 87.231.198.119
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/79646
Del: integrated -- https://master.php.net/note/delete/79646/integrated
Del: useless -- https://master.php.net/note/delete/79646/useless
Del: bad code -- https://master.php.net/note/delete/79646/bad+code
Del: spam -- https://master.php.net/note/delete/79646/spam
Del: non-english -- https://master.php.net/note/delete/79646/non-english
Del: in docs -- https://master.php.net/note/delete/79646/in+docs
Del: other reasons-- https://master.php.net/note/delete/79646
Reject -- https://master.php.net/note/reject/79646
Search -- https://master.php.net/manage/user-notes.php