Home >Backend Development >PHP Tutorial > PHP显示今天、今月、下月、今年的起点/终点时间戳

PHP显示今天、今月、下月、今年的起点/终点时间戳

WBOY
WBOYOriginal
2016-06-13 13:07:09949browse

PHP显示今天、今月、上月、今年的起点/终点时间戳
PHP显示今天、今月、上月、今年的起点/终点时间戳
$t    =   time();
$t1   =   mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$t2   =   mktime(0,0,0,date("m",$t),1,date("Y",$t));
$t3   =   mktime(0,0,0,date("m",$t)-1,1,date("Y",$t));
$t4   =   mktime(0,0,0,1,1,date("Y",$t));
$e1   =   mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$e2   =   mktime(23,59,59,date("m",$t),date("t"),date("Y",$t));
$e3   =   mktime(23,59,59,date("m",$t)-1,date("t",$t3),date("Y",$t));
$e4   =   mktime(23,59,59,12,31,date("Y",$t));
//测试
echo   date("当前   Y-m-d   H:i:s",$t)."   $t
";
echo   date("今天起点   Y-m-d   H:i:s",$t1)."   $t1
";
echo   date("今月起点   Y-m-d   H:i:s",$t2)."   $t2
";
echo   date("上月起点   Y-m-d   H:i:s",$t3)."   $t3
";
echo   date("今年起点   Y-m-d   H:i:s",$t4)."   $t4
";
//测试
echo   date("今天终点   Y-m-d   H:i:s",$e1)."   $e1
";
echo   date("今月终点   Y-m-d   H:i:s",$e2)."   $e2
";
echo   date("上月终点   Y-m-d   H:i:s",$e3)."   $e3
";
echo   date("今年终点   Y-m-d   H:i:s",$e4)."   $e4
";
结果:
当前 2011-05-24 15:42:55 1306222975
今天起点 2011-05-24 00:00:00 1306166400
今月起点 2011-05-01 00:00:00 1304179200
上月起点 2011-04-01 00:00:00 1301587200
今年起点 2011-01-01 00:00:00 1293811200
今天终点 2011-05-24 23:59:59 1306252799
今月终点 2011-05-31 23:59:59 1306857599
上月终点 2011-04-30 23:59:59 1304179199
今年终点 2011-12-31 23:59:59 1325347199

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