Home > php教程 > PHP源码 > php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法

php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法

PHP中文网
Release: 2016-05-25 17:04:04
Original
1211 people have browsed it

//php获取今日开始时间戳和结束时间戳
        $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
        $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
        echo "今日开始时间戳:".$beginToday.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$beginToday).&#39;<br>&#39;;
        echo "今日结束时间戳:".$endToday.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$endToday).&#39;<br>&#39;;
         //php获取昨日起始时间戳和结束时间戳
        $beginYesterday=mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)-1,date(&#39;Y&#39;));
        $endYesterday=mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;),date(&#39;Y&#39;))-1;
        echo "昨日开始时间戳:".$beginYesterday.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$beginYesterday).&#39;<br>&#39;;
        echo "昨日结束时间戳:".$endYesterday.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$endYesterday).&#39;<br>&#39;;
        //php获取上周起始时间戳和结束时间戳
        $beginLastweek=mktime(0,0,0,date(&#39;m&#39;),date(&#39;d&#39;)-date(&#39;w&#39;)+1-7,date(&#39;Y&#39;));
        $endLastweek=mktime(23,59,59,date(&#39;m&#39;),date(&#39;d&#39;)-date(&#39;w&#39;)+7-7,date(&#39;Y&#39;));
        echo "上周开始时间戳:".$beginLastweek.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$beginLastweek).&#39;<br>&#39;;
        echo "上周结束时间戳:".$endLastweek.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$endLastweek).&#39;<br>&#39;;
        //php获取本月起始时间戳和结束时间戳
        $beginThismonth=mktime(0,0,0,date(&#39;m&#39;),1,date(&#39;Y&#39;));
        $endThismonth=mktime(23,59,59,date(&#39;m&#39;),date(&#39;t&#39;),date(&#39;Y&#39;)); 
        echo "本月开始时间戳:".$beginThismonth.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$beginThismonth).&#39;<br>&#39;;
        echo "本月结束时间戳:".$endThismonth.&#39;----&#39;.date(&#39;Y-m-d H:i:s&#39;,$endThismonth).&#39;<br>&#39;;
Copy after login

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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template