如何根据时间/日期设置变量

时间:2014-02-06 02:23:24

标签: php

如何根据星期几和时间将变量$ a设置为特定值。

例如,在伪代码中:

Mon 09.00h - 16.59h, $a = 5,
Sat 12.00h - 13.00h, $a = 10

1 个答案:

答案 0 :(得分:0)

$time = time()%86400;
$date = date("D");
// since 9 hours = 32400 seconds and 16 hours and 59 minutes = 61140 seconds
if($date == "Mon" && $time >= 32400 && $time <= 61140){
$a = 5;
}
// since 12 hours = 43200 seconds and 13 hours = 46800 seconds
else if($date == "Sat" && $time >= 43200 && $time <= 46800){
$a = 10;
}