我试图根据日期范围显示商店的营业时间。除了在6月15日至9月1日之间使用夏令时之外,我需要显示正常小时数。我目前在我的代码中都有(下面),我只是评论一行。有人可以帮我实现这个自动化吗?包含基于日期范围的文件
<?php
//include ("content/summer_hours.inc");
include ("content/normal_hours.inc");
?>
我试图根据日期范围显示商店的营业时间。除了在6月15日至9月1日之间使用夏令时之外,我需要显示正常小时数。我目前在我的代码中都有(下面),我只是评论一行。有人可以帮我实现这个自动化吗?包含基于日期范围的文件
<?php
//include ("content/summer_hours.inc");
include ("content/normal_hours.inc");
?>
关众所周知的袖口......
$june15=strtotime("15 June ".date('Y'));
$sep1=strtotime("1 September ".date('Y'));
$now=time();
if ($now > $june15 && $now < $sep1){
include ("content/summer_hours.inc");
}
else{
include ("content/normal_hours.inc");
}
下面是一年中白天比较的另一种方法,如果它落在一年的日子,你正在寻找间看到。可能会更有效率。这可能是一个更快的方法。
$year = date('Y'); //Get the current year
$today = date('z'); //Get the day of the year.
$june15 = 166; //166th day of year
$sept01 = 244; //244th day of year
$isleap = (($year & 3) == 0 && (($year % 25) != 0 || ($year & 15) == 0)); //Is it a leap year.
if ($today > $june15 + $isleap && $today < $sept01 + $isleap) {
include ("content/summer_hours.inc");
} else {
include ("content/normal_hours.inc");
}
很好!感谢你们俩。 – donnelj
只需添加一个if语句来检查日期并包含正确的文件。 – Schleis
为什么把商店的时间放在单独的包含文件中? – crush
@crush - 我知道这不是必要的,但我喜欢将大部分html组件保留在我的php脚本之外,以便在我的模板中使用更清晰的代码。 – donnelj