如何計算已經從當前YEAR
到今天的星期日數。我也想計算已經從當前MONTH
到今天的星期日數量。計算當前年份和當前月份的星期日數量?
如
today is 14 April 2012 I should get 2 for the Number of Sundays
that are passed from the current month.
誰能給我一個提示或教程如何可以做到這一點?
如何計算已經從當前YEAR
到今天的星期日數。我也想計算已經從當前MONTH
到今天的星期日數量。計算當前年份和當前月份的星期日數量?
如
today is 14 April 2012 I should get 2 for the Number of Sundays
that are passed from the current month.
誰能給我一個提示或教程如何可以做到這一點?
嗯,我想這是很簡單的使用功能date()
//will give you the amount of sundays from the begining of the year
$daysTotal = ceil((date("z") - date("w"))/7);
//will give you the amount of sundays from the begining of the month
$daysTotal = ceil((date("j") - date("w"))/7);
我沒有測試它,你可能要檢查輪()函數的工作權在這種情況下,但該點被傳遞我想
祝你好運
非常感謝主席先生 – ScoRpion 2012-04-14 13:18:58
日期('W')可能會幫助你。檢查PHP手冊的格式 - http://php.net/manual/en/function.date.php。
不要忘記根據手冊 - ISO-8601週數,週數從星期一開始。 因此,即使這不是星期天,本週也會計算在內。所以在這種情況下減少數量1.
function get_sunday_since_year_start($today=null)
{
if($today==null) $today = time();
if(date('D',$today)=='Sun')
return Date('W',$today);
else
return Date('W',$today)-1;
}
function get_sunday_since_month_start()
{
return get_sunday_since_year_start()-get_sunday_since_year_start(strtotime(date('Y-m-01 00:00:00')));
}
看看這個http://stackoverflow.com/questions/336127/calculate-business-days。你可以在那裏找到你需要的一切。 – kpotehin 2012-04-14 10:37:53