Home > Backend Development > PHP Tutorial > PHP takes out the timestamp of Monday and Sunday_PHP Tutorial

PHP takes out the timestamp of Monday and Sunday_PHP Tutorial

WBOY
Release: 2016-07-15 13:22:09
Original
1266 people have browsed it

Get the timestamps of Monday and Sunday
You can see a lot of things through the following two examples of extracting the timestamps of Monday and Sunday. You need to keep thinking. The first one is better to extract the timestamp of the specified date, but how to extract the timestamp of Monday and Sunday? The second one is more practical.
*/

function getmonsun(){
    $curtime=time();
      
    $curweekday = date('w');

     //为0是 就是 星期七
    $curweekday = $curweekday?$curweekday:7;


    $curmon = $curtime - ($curweekday-1)*86400;
    $cursun = $curtime + (7 - $curweekday)*86400;
     
    $cur['mon'] = $curmon;
    $cur['sun'] = $cursun;

    return $cur;
}
    $cur = getmonsun();

    echo date('y-m-d',$cur['mon']);
    echo "rn";
    echo date('y-m-d',$cur['sun']);
 
//方法二 利用php strtotime函数

 echo strtotime('last monday');
 echo &#39;<br />&#39;;
 echo strtotime(&#39;next sunday&#39;);
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/447015.htmlTechArticleTo extract the timestamps of Monday and Sunday, you can see the following two examples of extracting the timestamps of Monday and Sunday. There are a lot of things to come out, so you have to keep thinking about it. The first one to take out the designated date...
Related labels:
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