我正在尝试显示一段持续7天的内容(现在的图片),然后更改为下一段内容。
在内容项目#6的第7天之后,我需要循环6件内容。我需要从内容项目#1开始。
我采用的一般方法是,获取UNIX时间戳,除以7天,模数除以总内容项。
我认为这是一个建议,但不清楚$timestamp
指的是什么?
$weeknumber = $ceil((time() – $starttimestamp) / 604800);
if ($weeknumber > {totalimages}) {
$ weeknumber = $weeknumber % {totalimages};
}
这(time() - $timestamp)
对我来说没有意义
我希望返回1-6(或0-5),然后根据该返回值执行/加载任何内容。我觉得我错过了它的一部分。
$unixStamp = time();
echo date('r', $unixStamp) . "<br />"; //outputs correct/current date
$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
echo "ARTICLE TO GRAB 1: ".$weekCount1;
echo '<br>';
$weekCount2 = (floor($unixStamp / 604800) % 6);
$weekCount2a = ($unixStamp / 604800) % 6;
$weekCount2b = (floor(time() - $unixStamp / 604800));
echo "ARTICLE TO GRAB 2: ".$weekCount2 .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2b .'<br>';
话虽如此,我还不清楚如何测试以确保它能正确更改/更新? (我是否会暂时在$ unixStamp中添加几天/几周来强制使用不同的日期?)
另一种尝试并尝试获得不同的值:
$unixStamp = time();
echo date('r', $unixStamp) . "<br /><br />"; //outputs correct/current date
$startDate = strtotime('2015-03-01 00:00:00');
$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6) + 1;
//$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6);
$weekCount2b = ($unixStamp / 604800) % 6;
$weekCount2c = (floor(time() - $unixStamp / 604800));
$weekCount2d = (ceil($unixStamp / 604800) % 6);
echo "ARTICLE TO GRAB 1: ".$weekCount1 .'<br>';
echo "ARTICLE TO GRAB 2a: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2b: ".$weekCount2b .'<br>';
echo "ARTICLE TO GRAB 2c: ".$weekCount2c .'<br>';
echo "ARTICLE TO GRAB 2d: ".$weekCount2d .'<br>';
我已经添加并更改了一个开始日期以从unixStamp中减去,以便在启动rotqation与unixStamp时获得时间差异形式并尝试获得返回。但是,无论开始日期如何,它都不会改变?
最新尝试:当我刷新时似乎更新,而不是关闭startDate:
$unixStamp = time();
$startDate = strtotime('2015-02-1 00:00:00');
$weekCount = ceil($unixStamp - $startDate / 604800);
echo "CONTENT ID TO GRAB: ".$weekCount .'<br>';
if ($weekCount > 6) {
$weekCount = $weekCount % 6;
echo "CONTENT TO GRAB: ".$weekCount;
}
答案 0 :(得分:1)
你可以使用一年中的周数,用你的模数:
$dayId = date('W') % 7;
date()
返回的数字将从0开始,每周递增到年末。因此,这将提供一个可靠的0 ... 6周期而没有太多代码。
答案 1 :(得分:0)
更新的代码:(现在似乎工作正常)
$unixStamp = time();
$startDate = strtotime('2015-03-27 00:00:00');
$weekCount = ceil(($unixStamp - $startDate) / 604800) - 1;
if ($weekCount > 6) {
$weekCount = $weekCount % 6;
}