2009-11-06 78 views

回答

1

可以工作嗎?

$start_timestamp = strtotime('2009-11-17'); 
$d1 = getdate($start_timestamp); 

$end_timestamp = mktime(
    0, 
    0, 
    0, 
    $d1['mon'] + 1 + floor($d1['mday']/16), // 1 before the 16th, then 2 
    15 * (1-floor($d1['mday']/16)),  //15 before the 16th, then 0 
    $d1['year'] 
); 
$end_date = date('Y-m-d', $end_timestamp); 
+0

我得到通知:在第一線 –

+0

遇到indate.php非合式數值對不起,我的代碼與時間戳工作。更改並測試它。 – goorj

+0

小修正,mktime函數的第四個參數應該是$ d1 ['mon'] + 1 + floor($ d1 ['mday']/16)而不是$ d1 ['month'] + 1 + floor($ d1 ['mday']/16),後者會在蛾部分產生01 –

1

這裏是另一種方式來做到這一點:

$dt = new DateTime($start_date); 
if ($dt->format('d') > 15) { 
    $day = 'last day'; 
} else { 
    $day = (15 - $dt->format('d')) . ' days'; 
} 
echo $dt->modify('next month ' . $day)->format('Y-m-d'); 
相關問題