Heim > Backend-Entwicklung > PHP-Tutorial > php获取 本月 本周 或者 下月 下周的 开始时间 结束时间_PHP教程

php获取 本月 本周 或者 下月 下周的 开始时间 结束时间_PHP教程

WBOY
Freigeben: 2016-07-20 11:15:32
Original
1270 Leute haben es durchsucht

<span <span <?php<br />$now_time</span> = <span time</span><span ();
</span><span $date</span>=<span date</span>("Y-m-d",<span $now_time</span><span );
</span><span function</span> get_date(<span $date</span>,<span $t</span>='d',<span $n</span>=0<span )
{
    </span><span if</span>(<span $t</span>=='d'<span ){
       </span><span $firstday</span> = <span date</span>('Y-m-d 00:00:00',<span strtotime</span>("<span $n</span> day"<span ));
       </span><span $lastday</span> = <span date</span>("Y-m-d 23:59:59",<span strtotime</span>("<span $n</span> day"<span ));
    }</span><span elseif</span>(<span $t</span>=='w'<span ){
       </span><span if</span>(<span $n</span>!=0){<span $date</span> = <span date</span>('Y-m-d',<span strtotime</span>("<span $n</span> week"<span ));}
       </span><span $lastday</span> = <span date</span>("Y-m-d 00:00:00",<span strtotime</span>("<span $date</span> Sunday"<span ));
       </span><span $firstday</span> = <span date</span>("Y-m-d 23:59:59",<span strtotime</span>("<span $lastday</span> -6 days"<span ));
    }</span><span elseif</span>(<span $t</span>=='m'<span ){
       </span><span if</span>(<span $n</span>!=0){<span $date</span> = <span date</span>('Y-m-d',<span strtotime</span>("<span $n</span> months"<span ));}
       </span><span $firstday</span> = <span date</span>("Y-m-01 00:00:00",<span strtotime</span>(<span $date</span><span ));
       </span><span $lastday</span> = <span date</span>("Y-m-d 23:59:59",<span strtotime</span>("<span $firstday</span> +1 month -1 day"<span )); 
    }
    </span><span return</span> <span array</span>(<span $firstday</span>,<span $lastday</span><span );
}
</span><span $day1</span>   = get_date(<span $date</span>,'d'<span );
</span><span $day2</span>   = get_date(<span $date</span>,'d',-1<span );
</span><span $week1</span> = get_date(<span $date</span>,'w'<span );
</span><span $week2</span> = get_date(<span $date</span>,'w',-1<span );
</span><span $month1</span> = get_date(<span $date</span>,'m'<span );
</span><span $month2</span> = get_date(<span $date</span>,'m',-1<span );
</span><span echo</span> '<pre class="brush:php;toolbar:false">'<span ;
</span><span print_r</span>(<span $day1</span>);<span //</span><span 今天</span>
<span print_r</span>(<span $day2</span>);<span //</span><span 昨天</span>
<span print_r</span>(<span $week1</span>);<span //</span><span 这周</span>
<span print_r</span>(<span $week2</span>);<span //</span><span 上周</span>
<span print_r</span>(<span $month1</span>);<span //</span><span 这月</span>
<span print_r</span>(<span $month2</span>);<span //</span><span 上月</span>
<span echo</span> '
Nach dem Login kopieren
';

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440173.htmlTechArticle$now_time = = ("Y-m-d", get_date( , ='d', =0 ( =='d' = ('Y-m-d 00:00:00', (" day" = ("Y-m-d 23:59:59", (" day" ( =='w' ( !=0){ = ('Y-m-d', (" week" = ("Y-m-d 00:00:00", (" Sunday"...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage