>  기사  >  백엔드 개발  >  PHP는 전날, 지난주, 지난 달, 지난 분기를 출력합니다.

PHP는 전날, 지난주, 지난 달, 지난 분기를 출력합니다.

高洛峰
高洛峰원래의
2016-11-29 10:33:021270검색

<?php
  
echo "<pre class="brush:php;toolbar:false">";
echo date("Y-m-d",strtotime("now")), "\n";
echo "<pre class="brush:php;toolbar:false">";
echo date("Y-m-d",strtotime("-1 week Monday")), "\n";
echo "<pre class="brush:php;toolbar:false">";
echo date("Y-m-d",strtotime("-1 week Sunday")), "\n";
echo "<pre class="brush:php;toolbar:false">";
echo date("Y-m-d",strtotime("+0 week Monday")), "\n";
echo "<pre class="brush:php;toolbar:false">";
echo date("Y-m-d",strtotime("+0 week Sunday")), "\n";
echo "<pre class="brush:php;toolbar:false">";
  
echo "*********第几个月:";
echo date(&#39;n&#39;); 
echo "<pre class="brush:php;toolbar:false">";
echo "*********本周周几:";
echo date("w"); 
echo "<pre class="brush:php;toolbar:false">";
echo "*********本月天数:";
echo date("t");
  
echo "<pre class="brush:php;toolbar:false">";
  
echo &#39;<br>上周:<br>&#39;;
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
echo "<pre class="brush:php;toolbar:false">";
echo &#39;<br>本周:<br>&#39;;
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
echo "<pre class="brush:php;toolbar:false">";
echo &#39;<br>上上月:<br>&#39;;
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-2,1,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m")-1,0,date("Y"))),"\n";
echo "<pre class="brush:php;toolbar:false">";
  
echo &#39;<br>上月:<br>&#39;;
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
echo "<pre class="brush:php;toolbar:false">";
echo &#39;<br>本月:<br>&#39;;
echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
echo "<pre class="brush:php;toolbar:false">";
   
echo "<pre class="brush:php;toolbar:false">";
$season = ceil((date(&#39;n&#39;))/3)-2;//上季度是第几季度
echo &#39;<br>上上季度:<br>&#39;;
echo date(&#39;Y-m-d H:i:s&#39;, mktime(0, 0, 0,$season*3-3+1,1,date(&#39;Y&#39;))),"\n";
echo date(&#39;Y-m-d H:i:s&#39;, mktime(23,59,59,$season*3,date(&#39;t&#39;,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(&#39;Y&#39;))),"\n"; 
 echo "<pre class="brush:php;toolbar:false">";
   
echo "<pre class="brush:php;toolbar:false">";
$season = ceil((date(&#39;n&#39;))/3)-1;//上季度是第几季度
echo &#39;<br>上季度:<br>&#39;;
echo date(&#39;Y-m-d H:i:s&#39;, mktime(0, 0, 0,$season*3-3+1,1,date(&#39;Y&#39;))),"\n";
echo date(&#39;Y-m-d H:i:s&#39;, mktime(23,59,59,$season*3,date(&#39;t&#39;,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(&#39;Y&#39;))),"\n"; 
 echo "<pre class="brush:php;toolbar:false">";
  
echo $season = ceil((date(&#39;n&#39;))/3);//当月是第几季度
echo &#39;<br>本季度:<br>&#39;;
echo date(&#39;Y-m-d H:i:s&#39;, mktime(0, 0, 0,$season*3-3+1,1,date(&#39;Y&#39;))),"\n";
echo date(&#39;Y-m-d H:i:s&#39;, mktime(23,59,59,$season*3,date(&#39;t&#39;,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(&#39;Y&#39;))),"\n";
   
$season = ceil((date(&#39;n&#39;))/3)+1;//当月是第几季度
echo &#39;<br>下季度:<br>&#39;;
echo date(&#39;Y-m-d H:i:s&#39;, mktime(0, 0, 0,$season*3-3+1,1,date(&#39;Y&#39;))),"\n";
echo date(&#39;Y-m-d H:i:s&#39;, mktime(23,59,59,$season*3,date(&#39;t&#39;,mktime(0, 0 , 0,$season*3,1,date("Y"))),date(&#39;Y&#39;))),"\n";
   
echo "<pre class="brush:php;toolbar:false">";
  
?>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.