本文整理匯總了PHP中date::set_year方法的典型用法代碼示例。如果您正苦於以下問題:PHP date::set_year方法的具體用法?PHP date::set_year怎麽用?PHP date::set_year使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類date
的用法示例。
在下文中一共展示了date::set_year方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array
function get_week_of_year()
{
$day = $this->day;
$month = $this->month;
$year = $this->year;
$mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$y_isleap = $this->is_leap_year();
$d = new date($this);
$d->set_year($this->year - 1);
$y_1_isleap = $d->is_leap_year();
$day_of_year_number = $day + $mnth[$month - 1];
if ($y_isleap && $month > 2) {
$day_of_year_number++;
}
// find Jan 1 weekday (monday = 1, sunday = 7)
$yy = ($year - 1) % 100;
$c = $year - 1 - $yy;
$g = $yy + intval($yy / 4);
$jan1_weekday = 1 + intval(($c / 100 % 4 * 5 + $g) % 7);
// weekday for year-month-day
$h = $day_of_year_number + ($jan1_weekday - 1);
$weekday = 1 + intval(($h - 1) % 7);
// find if Y M D falls in YearNumber Y-1, WeekNumber 52 or
if ($day_of_year_number <= 8 - $jan1_weekday && $jan1_weekday > 4) {
$yearnumber = $year - 1;
if ($jan1_weekday == 5 || $jan1_weekday == 6 && $y_1_isleap) {
$weeknumber = 53;
} else {
$weeknumber = 52;
}
} else {
$yearnumber = $year;
}
// find if Y M D falls in YearNumber Y+1, WeekNumber 1
if ($yearnumber == $year) {
if ($y_isleap) {
$i = 366;
} else {
$i = 365;
}
if ($i - $day_of_year_number < 4 - $weekday) {
$yearnumber++;
$weeknumber = 1;
}
}
// find if Y M D falls in YearNumber Y, WeekNumber 1 through 53
if ($yearnumber == $year) {
$j = $day_of_year_number + (7 - $weekday) + ($jan1_weekday - 1);
$weeknumber = intval($j / 7);
// kludge!!! - JMC
if ($jan1_weekday > 4) {
$weeknumber--;
}
}
return $weeknumber;
}