首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >每隔几天添加一个日期

每隔几天添加一个日期
EN

Stack Overflow用户
提问于 2010-05-04 01:39:01
回答 2查看 130关注 0票数 0

我有一些代码,生成灯具,我希望添加一个灯具日期的代码。

代码语言:javascript
运行
复制
$totalRounds = $teams - 1;
    $matchesPerRound = $teams / 2;
    $rounds = array();
    for ($i = 0; $i < $totalRounds; $i++) {
        $rounds[$i] = array();
    }

    for ($round = 0; $round < $totalRounds; $round++) {
        for ($match = 0; $match < $matchesPerRound; $match++) {
            $home = ($round + $match) % ($teams - 1);
            $away = ($teams - 1 - $match + $round) % ($teams - 1);
            // Last team stays in the same place while the others
            // rotate around it.
            if ($match == 0) {
                $away = $teams - 1;
            }

            $rounds[$round][$match] = "$user[$home]~$team[$home]@$user[$away]~$team[$away]";
        }
    }

$team是联盟中的球队数量。我想为每4天添加一个变量,并且对于每一轮生成的装备,我想在前一轮的基础上添加4天。

例如,如果今天是5月3日,我希望第一场比赛是5月3日,第二场比赛是5月7日,第三场比赛是5月11日。

我所说的fixture指的是圆形,它包括一组fixture!

如何在每次轮数增加时将4天添加到strotime变量中?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-05-04 02:39:31

如果我没理解错的话,你只是希望每一轮都有一个相关的日期。您已经有了一个$rounds数组,所以您不能创建一个对应的键值数组来保存舍入日期吗?

代码语言:javascript
运行
复制
...
$rounds = array();
$roundDates = array();
$curTime = time();
for ($i = 0; $i < $totalRounds; $i++) {
    $rounds[$i] = array();
    $numDays = $i * 4;
    $roundDates[$i] = strtotime("+".$numDays." days",$curTime);
}

foreach($roundDates as $time) echo date("Y-m-d",$time)."\n";
//gives
//2010-05-03
//2010-05-07
//2010-05-11
//etc
票数 0
EN

Stack Overflow用户

发布于 2010-05-04 01:43:08

你调查过strtotime吗?它允许如下语法:

代码语言:javascript
运行
复制
$future_date = strtotime('+4 days');
$even_further_in_the_future = strtotime('+4 days', $future_date);
$arbitrary_start_date = strtotime('+4 days', strtotime('May 25th, 2010'));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2759979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档