我目前正在尝试制作一个小型日历。
点击我的按钮,我调用一个AJAX函数,它将从我的数据库返回数据,并将其发送到我的自定义日历(完整的html(中。
我把第一个月定在十一月。
从2018年12月到2019年1月,我该如何处理这一年?
我有这个:
$newBeginDate = new DateTime($dateBegin, $timeZoneParis);
$lastDayThisMonth = new DateTime($newBeginDate->format('Y-m-t'));
$newBeginDate->modify('+1 month');
我有合适的月份,直到我试着去一月(什么都没发生(我被2018年12月卡住了,不能去2019年1月(,我不知道该怎么做(。
$newBeginDate->format('Y-m-t')
t
是给定月份的天数,而不是月份的日期。
尝试:
$newBeginDate->format('Y-m-d')
编辑:我知道你可能会使用它,因为你只使用这个函数来获取月份,但如果你从1月到2月,你要么会出错,要么会在3月初结束。
解决方案:
这是我的PHP代码:
$dateBegin = $currentYearPost. "-".$currentMonthPost."-01";
$dateEnd = $currentYearPost . "-".$currentMonthPost."-t";
$newBeginDate = new DateTime($dateBegin, $timeZoneParis);
if($_POST['next'] != ""){
$newBeginDate->modify('+1 month');
}else{
$newBeginDate->modify('-1 month');
}
$period = new DatePeriod($newBeginDate,new DateInterval('P1D'),$lastDayThisMonth);
什么也没发生,因为我用错了jQuery:
$('#nextMonth',#previousMonth'(.on('click',function(({
到$(文档(之外。准备好
$('#nextMonth',#previousMonth'(.live('click',function(({