Php obtains the timestamp of the current month, the beginning of last month, and the end of last month.
This example describes how to obtain the timestamp of the current month, the beginning of last month, and the end of last month by using php. We will share this with you for your reference. The details are 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 timestamp $ e_time = strtotime ($ endDay) at the beginning of the current month ); // The end timestamp of the current month
Last month
<? Php $ thismonth = date ('M'); $ thisyear = date ('y'); if ($ thismonth = 1) {$ lastmonth = 12; $ lastyear = $ thisyear-1;} else {$ lastmonth = $ thismonth-1; $ lastyear = $ thisyear;} $ lastStartDay = $ lastyear. '-'. $ lastmonth. '-1'; $ lastEndDay = $ lastyear. '-'. $ lastmonth. '-'. date ('T', strtotime ($ lastStartDay); $ B _time = strtotime ($ lastStartDay); // The timestamp at the beginning of last month $ e_time = strtotime ($ lastEndDay ); // last month Timestamp
The key here is t in the date function, which is used to obtain the number of days in the current month, 28 days, 29 days, 30 days, 31 days. The number of days at the end of the month.
PS: This site also provides a Unix timestamp conversion tool, including the timestamp operation methods in various common languages, for your reference:
Unix timestamp Conversion Tool:
Http://tools.jb51.net/code/unixtime