上次做项目时,发现一个问题,这里记录一下:
在使用date函数获取上一个月最后一天或下个月最后一天时,如果当前日期是31号,获取的数据有问题。
// 2019-12-01 正确应该是 2019-11-30 date('y-m-d', strtotime('+1 month', strtotime('2019-10-31'))); // 2019-10-01 正确应该是 2019-09-30 date('y-m-d', strtotime('-1 month', strtotime('2019-10-31')));
可以使用“last day of”来获取最后一天。
// 2019-11-30 date('y-m-d', strtotime('last day of +1 month', strtotime('2019-10-31'))); // 2019-09-30 date('y-m-d', strtotime('last day of -1 month', strtotime('2019-10-31')));
测试后发现获取第一天数据也有同样的问题:
相应的可以使用“first day of”来获取第一天数据。
// 2019-11-01 date('y-m-d', strtotime('first day of +1 month', strtotime('2019-10-31'))); // 2019-09-01 date('y-m-d', strtotime('first day of -1 month', strtotime('2019-10-31')));
如对本文有疑问, 点击进行留言回复!!
php 使用 yansongda/pay 进行微信,支付宝支付
Codeforces Round #658 (Div. 2) (C1、C2)
van-uploader + thinkphp6.0 图片上传
网友评论