This article describes how PHP obtains the current month and the month and month-end timestamp. Share to everyone for your reference, specific as follows:
Current month
<?php
$thismonth = date (' m ');
$thisyear = Date (' Y ');
$startDay = $thisyear. '-' . $thismonth. '-1 ';
$endDay = $thisyear. '-' . $thismonth. '-' . Date (' t ', Strtotime ($startDay));
$b _time = Strtotime ($startDay);//The beginning of the current month timestamp
$e _time = Strtotime ($endDay);//month-end timestamp of the current month
Last month
<?php
$thismonth = date (' m ');
$thisyear = Date (' Y ');
if ($thismonth = = 1) {
$lastmonth =;
$lastyear = $thisyear-1;
} else {
$lastmonth = $thismonth-1;
$lastyear = $thisyear;
}
$lastStartDay = $lastyear. '-' . $lastmonth. '-1 ';
$lastEndDay = $lastyear. '-' . $lastmonth. '-' . Date (' t ', Strtotime ($lastStartDay));
$b _time = Strtotime ($lastStartDay); time stamp
$e _time = Strtotime ($lastEndDay) last month;/month
The key here is the T in the Date function, which is used to get the number of days that the current month contains, 28 days, 29 days, 30 days, 31 days. How many days, the month is the number.
PS: This site also provides a UNIX timestamp conversion tool, including a variety of common language for time stamping operation methods, provided to you for reference:
Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime
More about PHP Interested readers can view the site topics: "PHP date and Time usage summary", "PHP Mathematical Calculation Skills Summary", "PHP Array" operation Skills Encyclopedia, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Regular Expression Usage summary, "Summary of PHP operations and operator usage", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.