Forum Moderators: coopster
function date_at_timezone($format, $locale, $timestamp=null){
if(is_null($timestamp)) $timestamp = time();
//Prepare to calculate the time zone offset
$current = time();
//Switch to new time zone locale
$tz = date_default_timezone_get();
date_default_timezone_set($locale);
//Calculate the offset
$offset = time() - $current;
//Get the date in the new locale
$output = date($format, $timestamp - $offset);
//Restore the previous time zone
date_default_timezone_set($tz);
return $output;
}
//Examples
$t = time();
print date("g:i A T", $t); //4:16 PM PDT
print date_at_timezone("g:i A T", "America/Los_Angeles", $t); //7:16 PM EDT
print date_at_timezone("g:i A T", "Pacific/Samoa", $t); //12:16 PM SST
print date("g:i A T", $t); //4:16 PM PDT
$time = date(H);
if ($time <18 ¦¦ $time > 22)
{
display_one_thing();
}
else
{
display_other_thing();
}
$time = date(H:i);
if ($time < 08:30 || $time > 17:00)
{
display_one_thing();
}
else
{
display_other_thing();
} <?php
function date_at_timezone($format, $locale, $timestamp=null){
if(is_null($timestamp)) $timestamp = time();
//Prepare to calculate the time zone offset
$current = time();
//Switch to new time zone locale
$tz = date_default_timezone_get();
date_default_timezone_set($locale);
//Calculate the offset
$offset = time() - $current;
//Get the date in the new locale
$output = date($format, $timestamp - $offset);
//Restore the previous time zone
date_default_timezone_set($tz);
return $output;
}
$t = time();
$time = date_at_timezone("Hi", "America/Los_Angeles", $t);
if ($time > '0830' && $time < '1700')
{
echo 'Business Hours';
}
else
{
echo 'After Hours';
}
?>
if (($time > 0830) && ($time < 1700)){
echo 'Business Hours';
exit;
}
else{
echo 'After Hours';
exit;
}