문제

<?php 

$time = date('Hi');

if ($time > 0030) {
    echo "closed";
} elseif ($time >= 0800) {
    echo "open";
}
?>

This is the code i'm using for a client's website. In short it's a code that'll show if the client's business is open or not.

My client's working hours are between 8am to 12:30am.

I was wondering if there's an easier way of doing this or am I doing this right?

올바른 솔루션이 없습니다

다른 팁

Try this:

<?php 
date_default_timezone_set('Asia/Calcutta'); # set timezone according to your requirement
$now = new DateTime();
$start = new DateTime('today 08:00:00');
$end = new DateTime('tomorrow  00:30:00');
if ($start <= $now && $now < $end) {
    echo "open";
}
else{
    echo "close";
}
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top