Php 需要帮助为在线商店创建日期/时间功能吗
我正在编写一个函数,该函数将在商店是否打开时输出给用户 我编写了一个名为is_store_open()的函数,其中包含一个名为$day的变量,该变量将分配一周中的当前日期 假设今天是星期六。它找到“星期六”的情况,并检查星期六的开放时间和关闭时间 我面临的问题是,周六午夜过后商店什么时候开门。那么它就不会在周六检查这个案子了 相反,我将在周日检查这个案例。这不是我想要的,因为它会显示商店在“星期六”仍然营业时是关闭的 我在下面写了一个函数,检查前一天的关闭时间是否大于当前时间。如果它是真的,那么返回真的,我想这应该可以解决问题 但当我写到$saturday\u close未定义时,它会给我一个错误。我猜是因为它在switch语句中,它不等于那天 我对如何设置这个有点困惑。如果有人有什么建议,我将非常感谢你的帮助。谢谢Php 需要帮助为在线商店创建日期/时间功能吗,php,datetime,Php,Datetime,我正在编写一个函数,该函数将在商店是否打开时输出给用户 我编写了一个名为is_store_open()的函数,其中包含一个名为$day的变量,该变量将分配一周中的当前日期 假设今天是星期六。它找到“星期六”的情况,并检查星期六的开放时间和关闭时间 我面临的问题是,周六午夜过后商店什么时候开门。那么它就不会在周六检查这个案子了 相反,我将在周日检查这个案例。这不是我想要的,因为它会显示商店在“星期六”仍然营业时是关闭的 我在下面写了一个函数,检查前一天的关闭时间是否大于当前时间。如果它是真的,那么
function is_store_open(){
$set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
$day = date("l", $set_time);
$time_now = mktime("00", "00", "00"); // Now lets say the time now is 12:00am
switch ($day) {
case "Saturday":
$open = "11:00";
$saturday_close = "1:00";
break;
case "Sunday";
if($saturday_close > $time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
return true;
} else {
$open = "2:00";
$close = "22:00";
}
break;
}
这家商店星期六凌晨一点不开门。像这样想吧-sat:09:00-23:59:59。孙:00:00-01:00我知道。这是为餐馆准备的,他们的商店就是这样设立的。他们周六上午3点关门,周日上午9点开门。如果你用谷歌搜索餐厅的营业时间,它会说。星期六上午11:00-5:00。没关系!。我想出了一些办法。谢谢你的帮助。你能在这里发布你的解决方案给未来的读者吗。堆栈上有太多的“很酷,我解决了”问题。太棒了!记住也要把你的答案标记为正确。
class StoreOperationHours {
public $time_now;
public function __construct() {
//$this->time_now = mktime("2", "00", "00" ); // Now lets say the time now is 12:00am;
$this->time_now = mktime(date('H'), date('i'), date('s'));
}
public $SaturdayOpenHours = "11:00";
public $SaturdayClosingHours = "1:08:00";
public $SundayOpenHours = "11:00";
public $SundayCloseHours = "23:00";
public function IsStoreOpen() {
//$set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
$day = date("l", time());
switch ($day) {
case "Saturday":
$this->SaturdayOpenHours;
$this->SaturdayClosingHours;
break;
case "Sunday";
if(strtotime($this->SaturdayClosingHours) >= $this->time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
return true;
} elseif($e) {
return false;
}
break;