在中间显示当天 [英] Show current day in the middle

查看:37
本文介绍了在中间显示当天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个while循环,显示5天.第一天是当天,其他天是第二天.这是我的代码:

I have a while loop that shows 5 days. The first day is the current day and the other ones are the next 4. This is my code:

$datetime = new \DateTime();

$listItem = array('<li class="active">', '</li>');

$i = 0;
while (true) {
    if ($i === 5) break;

    if ($datetime->format('N') === '7' && $i === 0) {
        $datetime->add(new \DateInterval('P1D'));
        continue;        
    }

    echo $listItem[0] . $datetime->format('D d-m') . $listItem[1];
    $listItem = array('<li>', '</li>');    

    $datetime->add(new \DateInterval('P1D'));

    $i++;
}

结果看起来像这样:

我的问题是,我希望今天在中间.星期六是当前日期.你知道该怎么做吗?

My problem is, I want the current day to be in the middle. Where saturday is should be the current day. Do you know how to do this?

先谢谢了.

推荐答案

请尝试以下代码:

$datetime = new \DateTime();

$listItem = array('<li">', '</li>');
$listItem_active = array('<li class="active">', '</li>');

$i = 0;
while (true) {

    if ($i === 5) break;

    if ($datetime->format('N') === '7' && $i === 0) {
        $datetime->add(new \DateInterval('P1D'));
        continue;        
    }

    if($i===0){
        $today = $datetime->format('D d-m');
    }
    if($i===3){
        echo $listItem_active[0] . $today . $listItem_active[1];
    }
    if($i!=0){
        echo $listItem[0] . $datetime->format('D d-m') . $listItem[1];
    }

    $listItem = array('<li>', '</li>');    

    $datetime->add(new \DateInterval('P1D'));

    $i++;
}

这篇关于在中间显示当天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆