Home > Backend Development > PHP Tutorial > Code example of how to display the start/end timestamps of today, this month, last month, and this year in PHP

Code example of how to display the start/end timestamps of today, this month, last month, and this year in PHP

怪我咯
Release: 2023-03-13 10:32:02
Original
1548 people have browsed it

PHPDisplay the starting/end point of today, this month, last month, and this yearTime stamp code, friends who need it can refer to it.

$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<br>”; 
echo date(“今天起点 Y-m-d H:i:s”,$t1).” $t1<br>”; 
echo date(“今月起点 Y-m-d H:i:s”,$t2).” $t2<br>”; 
echo date(“上月起点 Y-m-d H:i:s”,$t3).” $t3<br>”; 
echo date(“今年起点 Y-m-d H:i:s”,$t4).” $t4<br>”; 
//测试 
echo date(“今天终点 Y-m-d H:i:s”,$e1).” $e1<br>”; 
echo date(“今月终点 Y-m-d H:i:s”,$e2).” $e2<br>”; 
echo date(“上月终点 Y-m-d H:i:s”,$e3).” $e3<br>”; 
echo date(“今年终点 Y-m-d H:i:s”,$e4).” $e4<br>”;
Copy after login

Results:
Current 2011-05-24 15:42:55 1306222975
Today’s starting point 2011-05-24 00:00:00 1306166400
This month’s starting point 2011-05-01 00:00:00 1304179200
Last month’s starting point 2011-04-01 00:00:00 1301587200
This year’s starting point 2011-01-01 00:00:00 1293811200
Today’s end point 2011-05-24 23 :59:59 1306252799
This month’s end point 2011-05-31 23:59:59 1306857599
Last month’s end point 2011-04-30 23:59:59 1304179199
This year’s end point 2011-12-31 23: 59:59 1325347199

The above is the detailed content of Code example of how to display the start/end timestamps of today, this month, last month, and this year in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template