這些功能似乎解決我的問題,但更遙遠的多年試驗可能是必要的:
// The N option gives the normal week day, arithmetic makes it return my custom week days
function getDayOfWeek(\DateTimeImmutable $date)
{
return ($date->format('N') + 2) % 7;
}
function getWeekNumber(\DatetimeImmutable $date)
{
// Recursive function that loops through every day until it gets the start of a week
$startOfWeek = function (\DateTimeImmutable $date) use (&$startOfWeek) {
return (getDaysOfWeek($date) === 1)
? $date : $startOfWeek($date->modify('+1 day'));
};
// The z option tells us what day of the year this is,
// not a 100% sure this step is necessary
if (getDayOfWeek($date === 1) {
$nbDays = $date->format('z');
else {
$nbDays = $startOfWeek($date->modify('-7 days'))->format('z');
}
// Divides by the number of days in a week to get the number of weeks
return ceil($nbDays/7);
}
周依據是什麼號碼?自今年年初以來? http://stackoverflow.com/q/4896452/56778對你有什麼用處?本頁面顯示的其他相關問題如何(下方和右方)?或者,也許http://stackoverflow.com/q/30056515/56778將是有用的。你需要做一點研究。 –
你如何定義「周編號」?是從某個日期開始還是你是指一週內的數字(星期六= 1,星期日= 2等)? – toonice
請正確地擴展您的需求。即具有樣本投入和預期產出,特別是在一年左右的日期。如果你有一個基於本週不同開始日期的工作實施,我認爲應該可以通過抵消這一天來僞造它。 –