2010-05-09 91 views

回答

1

先將其轉換爲一個時間戳(的strtotime,mktime,等等)。所以我認爲$ tm是00:00:00的時間戳。

$w = date("w", $tm); 
echo(date("Y-D-m", $tm - (86400 * $w))); 
echo(date("Y-D-m", $tm + 86400 * (6 - $w))); 
2

DateTime隨着(PHP 5.2+):

function weekBorders($date) { 
    $borders = array(); 
    $borders['first'] = new DateTime($date->format('Y-m-d') .' - '. $date->format('w') .' days'); 
    $borders['last'] = new DateTime($date->format('Y-m-d') .' + '. (6 - $date->format('w')) .' days'); 
    return $borders; 
} 
相關問題