Home > Backend Development > PHP Tutorial > Two ways to get time in PHP excluding Saturdays and Sundays_PHP Tutorial

Two ways to get time in PHP excluding Saturdays and Sundays_PHP Tutorial

WBOY
Release: 2016-07-13 10:26:20
Original
1133 people have browsed it

Today I will share with you a function that obtains a timestamp 10 days later. The key to the program is that it does not need to count Saturdays and Sundays. If you have other needs. It can be changed to N days. It’s not Saturday and Sunday anyway. Ha ha.

//方法一:
<&#63;php
$now = time(); //指定日期用法 $now = strtotime('2014-01-08') ;
$day = 3600*24;
$total = 12;

$days =array() ;

for ($i=2;$i<$total;$i++)
{
    $timer = $now+$day*$i;
    $num= date("N",$timer)-2; //周一开始
    if($num>=-1 and $num<=3)
    {
        if(count($days)>=10) break;
        $days[]=date("Y-m-d",$now+$day*$i);
        $total +=1 ;// $total==12 &#63;$total+1:$total;

    }else
    {
        $total = $total==12 &#63;$total+1:$total;
    }
}
$i=1;
foreach($days as $day)
{

    echo "$i===>".$day."\n";
    $i++;
}


//方法二:
function get_days ($date="")
{
    $now = empty($date)&#63;time():strtotime($date);
    $days = array();
    $i = 2;
    while(count($days)<10)
    {
        $timer = $now+3600*24*$i;
        $num= date("N",$timer)-2; //周一开始
        if($num>=-1 and $num<=3)
        {
            $days[]=date("Y-m-d",$now+3600*24*$i);
        }
        $i++;
    }

 return $days;
}
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824736.htmlTechArticleToday I would like to share with you a function that obtains a timestamp 10 days later. The key to the program is that it does not need to be Count on Saturdays and Sundays. If you have other needs. It can be changed to N days. Anyway...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template