这是代码Jquery代码,其中我将当前日期时间作为time(),然后将其设置为currentDate值
function getNextMonth(nextMonth)
{
var currentDate = $('#currentDate').val();
if(currentDate =='')
{
currentDate = 0;;
}
else
{
currentDate = $('#currentDate').val();;
}
var billingStatus = $('#billingStatus').val();
var userId = $('#userId').val();
var data = {
currentDate: currentDate,
billingStatus: billingStatus,
userId: userId,
nextMonth: nextMonth
};
console.log(data);
//alert($('#currentDate').val());
$.ajax({
url: $('#site_url').val() + 'people/timesheet/set_date',
type: 'POST',
data: data,
success: function(theResponse){
console.log(theResponse);
//alert(theResponse);
$('.monthlyWrap').html(theResponse);
$('#monYear').html($('#monthYear').val());
//$('#topLoadingWrap').hide();
//notify('Log Time deleted successfully!', 'success')
}
});
}
这是处理来自currentDate值
的数据的代码<div class="monthlyWrap">
<?php
//$timestamp = strtotime('next Sunday');
$days = array();
$month_start = (date('N', strtotime('01-'.$currentMonth, $currentDate))+1)%8;
$monthSt= (date('N', strtotime('00-'.$currentMonth)));
$date = $currentDate;
$day = date('d', $date) ;
$month = date('m', $date);
$year = date('Y', $date) ;
$days_in_month = cal_days_in_month(0, $month, $year) ;
$weeks = ceil(($monthSt + $days_in_month) / 7);
$yr = date('Y', $date) ;
$mon = date('m', $date) ;
//$test= date('m/d/Y h:i:s a', time());
for ($year = $yr; $year <= $yr; $year++){
for ($month = $mon; $month <= $mon; $month++){
$firstday = date("w", mktime(0, 0, 0, $month, 1, $year));
$lastday = date("t", mktime(0, 0, 0, $month, 1, $year));
$no_of_weeks = 1;
$count_weeks = 0;
while($no_of_weeks <= ($lastday+$firstday)){
$no_of_weeks += 1;
$count_weeks++;
}
//echo "Number Of weeks in Month=$month Year=$year = $count_weeks <br>";
//echo "firstday=$firstday lastday=$lastday no_of_weeks = $no_of_weeks <br>";
}
}
if($count_weeks == 5)
{
$totalColumn = 40;
}
else
{
$totalColumn = 48;
}
$k=1;
$i=1;
$c=1;
$currentDay =0;
$total_hours ='';
$total_minutes ='';
for ($j = 1; $j <= $totalColumn; $j++)
{
if($i%8 == 0)
{
?>
<div class="daysOfMonth" style="border-right:1px solid #DDDDDD;">
<div style="float:left;padding:40px 30px">
<?php
if($total_hours ==0)
{
echo '';
}
else
{
$tot_min = intval($total_minutes/60);
$total_remain = intval($total_minutes%60);
if($total_remain==0)
{
$total_remain ='00';
}
else
{
$total_remain =$total_remain ;
}
echo $total_hours+$tot_min.':'.$total_remain;
}
?>
</div>
</div>
<?php
}
else
{
if($j>=$month_start && $k<=$days_in_month)
{
$month_start_day = strtotime('01-'.$currentMonth);
$days[] = strftime('%a', $month_start_day);
$month_start_day = strtotime('+1 day', $month_start_day);
if($currentDay ==0)
{
$currentDay = (date('N', $month_start_day) + $currentDay );
}
else
{
$currentDay = (date('N', $month_start_day) +$k-1)%7 ;
}
if($currentDay == 0 || $currentDay==1)
{
$backgroundColor = 'background-color: #E7ECF0;';
}
else
{
$backgroundColor = '';
}
?>
<div class="daysOfMonth" style="border-right:1px solid #DDDDDD;<?=$backgroundColor?>"><?=$k;?>
<div style="float:left;width:80px;height:60px;overflow:hidden">
<?php
$currentDateMonthYear = date('Y-m', $date) ;
$orgId = $this->session->userdata('CCINTORGID');
$userType = $this->session->userdata('CCINTUTYPE');
if($userType == 'SUPER_ADMIN' || $userType == 'ADMIN' || $userType == 'OWNER' )
{
$hoursDetail = $this->timesheet_model->get_montly_timesheet($orgId, $currentDateMonthYear, $userId, $billingStatus);
}
else
{
$loggedInId = $this->session->userdata('CCINTUID');
$hoursDetail = $this->timesheet_model->get_montly_timesheet($orgId, $currentDateMonthYear, $userId, $billingStatus, $loggedInId);
}
if($i==9 || $i==17 || $i==25 || $i==33 || $i==41)
{
$total_hours =' ';
$total_minutes ='';
}
if($hoursDetail)
{
$hours = '';
$minutes ='';
foreach($hoursDetail as $row)
{
//print $row['hours'];
$hoursDate = $row['date'];
$hoursDay = date('d', strtotime($hoursDate)) ;
if($hoursDay==$k)
{
?>
<div class="hoursDiv"><?php //echo $hours[$k]
if($hoursDay==$k)
{
//$hours += $row['hours'];
$time = explode(':', $row['hours']);
$hours += $time[0];
$minutes += $time[1];
}
else
{
echo $hours ='';
echo $minutes ='';
}
?>
</div>
<?php
}
}
if($hours !=0 || $minutes !=0)
{
if($minutes==0)
{
$minutes ='00';
}
else
{
$minutes =$minutes ;
}
echo '<div style="padding:20px 30px">'.$hours.':'.$minutes.'</div>';
}
$total_hours = $hours + $total_hours;
$total_minutes = $minutes + $total_minutes;
}
?>
</div>
</div>
<?php
$k++;
$currentDay++;
}
else
{
?>
<div class="daysOfMonth" style="border-right:1px solid #DDDDDD;"> </div>
<?php
}
}
$i++;
}
?>
<div class="daysOfMonth" style="border-top:0px;border-right:1px solid #DDDDDD;float:right;margin-right:1px;height:97px">
<div style="padding:35px 30px">
<?php
if((isset($totalHours['totalHours'])) || isset($totalHours['totalMinutes']))
{
if($totalHours['totalMinutes']==0)
{
$totalMin ='00';
}
else
{
$totalMin =$totalHours['totalMinutes'] ;
}
$totalMin = intval($totalMin/60);
$totalRemain = intval($total_minutes%60);
if($totalRemain==0)
{
$totalRemain ='00';
}
else
{
$totalRemain =$totalRemain ;
}
print $totalHours['totalHours']+$totalMin.':'.$totalRemain;
}
?>
</div>
</div>
<div style="float:right;padding:40px 30px">Total Hours</div>
<input type="hidden" name="currentDate" id="currentDate" value="<?=$currentDate?>" />
<input type="hidden" name="monthYear" id="monthYear" value="<?=$monthYear?>" />
</div>
所以,当我点击下一步时它没有显示下个月(即)2月有人会帮助我!
答案 0 :(得分:0)
我通过将(28 * 24 * 60 * 60)的值添加到 currentDate 来得到答案:D