php获取月初和月尾时间
source link: http://abcdxyzk.github.io/blog/2021/01/22/lang-php-month/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
php获取月初和月尾时间
2021-01-22 21:30:00
#### 获取当前时间的月初月尾 ``` echo date("Y-m-01", time()); echo PHP_EOL; echo date('Y-m-t', time());
// 输出 2017-09-01 2017-09-30 ```
#### 获取上一月的月初月尾 ``` echo date("Y-m-01", strtotime('-1 month')); echo PHP_EOL; echo date('Y-m-t', strtotime('-1 month'));
// 输出 2017-08-01 2017-08-31 ```
#### 获取下一月的月初月尾 ``` echo date("Y-m-01", strtotime('+1 month')); echo PHP_EOL; echo date('Y-m-t', strtotime('+1 month'));
// 输出 2017-10-01 2017-10-31 ```
Posted by kk
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK