Home  >  Article  >  php教程  >  php 取出周一和周日的时间戳

php 取出周一和周日的时间戳

WBOY
WBOYOriginal
2016-06-13 10:59:111468browse

取出周一和周日的时间戳
能过下面两款取出周一和周日的时间戳实例可以看得出来很多的东西,要不断的思想哦,第一个自定的取出指定日期的时间戳比较好,但是如何是取出周一和周日第二个就更实用了。
*/

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;);

Statement:
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