PHP Time Script
Posted: Fri Aug 28, 2009 4:53 pm
I'm trying to make a script that can produce a CSS class upon a certain time of the day. I found the script below and gave it a shot hoping that I could save some time, but what I found is that this script is very inaccurate as it is outputting "midnight" while it is in fact around 4PM.
Below is the script:
I can do the leg work, but I'm not sure where to start exactly as I've never messed around with the PHP time functions, etc. Where would I start? Would it be with making a Unix time stamp or something or should I try to do something else to make it more accurate?
Below is the script:
Code: Select all
function timeBG(){
$hourOffset = 0;
$hourOffset = ($hourOffset * 3600);
$currentHour = date("G",time() + $hourOffset);
if($currentHour < 4){$time="midnight";}
else if($currentHour < 7){$time="dawn";}
else if($currentHour < 11){$time="morning";}
else if($currentHour < 13){$time="noon";}
else if($currentHour < 16){$time="afternoon";}
else if($currentHour < 19){$time="dusk";}
else if($currentHour < 22){$time="evening";}
else{$time="midnight";}
echo $time;
}