从 PHP 日期获取周数(年份)

Get week number (in the year) from a date PHP

我想date并计算出它的周数。

到目前为止,我有以下内容。它应该是 42 时返回 24。

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

数字颠倒是错误的巧合吗?还是我快到了?


今天,使用 PHP 的 DateTime 对象更好:

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

这是因为在mktime()中,它是这样的:

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

因此,您的订单是错误的。

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

使用 PHP 的日期函数

http://php.net/manual/en/function.date.php

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

这得到今天的日期,然后告诉一周的周数

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$week = $date->format("W");

echo"Weeknummer: $week";

mktime(hour, minute, second, month, day, year);

<?php

$ddate ="2012-10-18";

$duedt = explode("-", $ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:" . $week;

?>

$date_string ="2012-10-18";

echo"Weeknummer:" . date("W", strtotime($date_string));

date("W", $yourdate)

<?php

$date=date("W");

echo $date." Week Number";

?>

<?php echo date("W", strtotime("2012-10-18")); ?>

<?php echo date("Weeknumber: W", strtotime("2012-10-18 01:00:00")); ?>

<?php echo date("Weeknumber: W", strtotime($MY_DATE)); ?>

/**

* calcweek("2018-12-31") => 1901

* This function calculates the production weeknumber according to the start on 

* monday and with at least 4 days in the new year. Given that the $date has

* the following format Y-m-d then the outcome is and integer.

*

* @author M.S.B. Bachus

*

* @param date-notation PHP"Y-m-d" showing the data as yyyy-mm-dd

* @return integer

**/

function calcweek($date) {

 // 1. Convert input to $year, $month, $day

 $dateset   = strtotime($date);

 $year     = date("Y", $dateset);

 $month    = date("m", $dateset);

 $day     = date("d", $dateset);



 $referenceday = getdate(mktime(0,0,0, $month, $day, $year));

 $jan1day   = getdate(mktime(0,0,0,1,1,$referenceday[year]));



 // 2. check if $year is a leapyear

 if ( ($year%4==0 && $year%100!=0) || $year%400==0) {

  $leapyear = true;

 } else {

  $leapyear = false;

 }



 // 3. check if $year-1 is a leapyear

 if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {

  $leapyearprev = true;

 } else {

  $leapyearprev = false;

 }



 // 4. find the dayofyearnumber for y m d

 $mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);

 $dayofyearnumber = $day + $mnth[$month-1];

 if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }



 // 5. find the jan1weekday for y (monday=1, sunday=7)

 $yy = ($year-1)%100;

 $c = ($year-1) - $yy;

 $g = $yy + intval($yy/4);

 $jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);



 // 6. find the weekday for y m d

 $h = $dayofyearnumber + ($jan1weekday-1);

 $weekday = 1+(($h-1)%7);



 // 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53

 $foundweeknum = false;

 if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {

  $yearnumber = $year - 1;

  if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {

   $weeknumber = 53;

  } else {

   $weeknumber = 52;

  }

  $foundweeknum = true;

 } else {

  $yearnumber = $year;

 }



 // 8. find if y m d falls in yearnumber y+1, weeknumber 1

 if ( $yearnumber == $year && !$foundweeknum) {

  if ( $leapyear ) {

   $i = 366;

  } else {

   $i = 365;

  }

  if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {

   $yearnumber = $year + 1;

   $weeknumber = 1;

   $foundweeknum = true;

  }

 }



 // 9. find if y m d falls in yearnumber y, weeknumber 1 through 53

 if ( $yearnumber == $year && !$foundweeknum ) {

  $j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);

  $weeknumber = intval( $j/7 );

  if ( $jan1weekday > 4 ) { $weeknumber--; }

 }



 // 10. output iso week number (YYWW)

 return ($yearnumber-2000)*100+$weeknumber;

}

strftime('%G-%V',strtotime("2017-01-01"))
php -m
$dateTime = new DateTime('21-09-2020 09:00:00');

echo $dateTime->format("W"); // string '39'



$intlCalendar = IntlCalendar::fromDateTime ('21-09-2020 09:00:00');

echo $intlCalendar->get(IntlCalendar::FIELD_WEEK_OF_YEAR); // integer 39

$thisYear ="2020";

$thisDate ="2020-04-24"; //or any other custom date

$weeknr = date("W", strtotime($thisDate)); //when you want the weeknumber of a specific week, or just enter the weeknumber yourself



$tempDatum = new DateTime();

$tempDatum->setISODate($thisYear, $weeknr);

$tempDatum_start = $tempDatum->format('Y-m-d');

$tempDatum->setISODate($thisYear, $weeknr, 7);

$tempDatum_end = $tempDatum->format('Y-m-d');



echo $tempDatum_start //will output the date of monday

echo $tempDatum_end // will output the date of sunday

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[1], $duedt[2],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

function week_number($n)

{

  $w = date('w', $n);

  return 1 + date('z', $n + (6 - $w) * 24 * 3600) / 7;

}



$n = strtotime('2022-12-27');

printf("%s: %d\

", date('D Y-m-d', $n), week_number($n));

$now = Zend_Date::now();

$week = $now->get(Zend_Date::WEEK);

// 10

<?php $date=date("W"); echo"Week" . $date; ?>"

<?php $date=date("W"); echo"Week" . ($date - 1); ?>

$day_count = date('N',strtotime('2018-12-31'));

$week_count = date('W',strtotime('2018-12-31'));  





if($week_count=='01' && date('m',strtotime('2018-12-31'))==12){

  $yr_count = date('y',strtotime('2018-12-31')) + 1;

}else{

  $yr_count = date('y',strtotime('2018-12-31'));

}

$weeknumber = date("W"); //number week in year

$dayweek = date("w"); //number day in week

if ($dayweek =="6")

{

  $weeknumberint = (int)$weeknumber;

  $date2int++; 

  $weeknumber = (string)$date2int;

}



echo $date2;
15
$date_string ="2012-10-18";

$date_int = strtotime($date_string);

$date_date = date($date_int);

$week_number = date('W', $date_date);

echo"Weeknumber: {$week_number}.";

date( 'W', strtotime("2017-01-01 + 1 day" ) );

function last_monday($date) 

{

  if (!is_numeric($date))

    $date = strtotime($date);

  if (date('w', $date) == 1)

    return $date;

  else

    return date('Y-m-d',strtotime('last monday',$date));

}

$date = '2021-01-04'; //Enter custom date

$year = date('Y',strtotime($date));

$date1 = new DateTime($date);

$ldate = last_monday($year."-01-01");

$date2 = new DateTime($ldate);

$diff = $date2->diff($date1)->format("%a");

$diff = $diff/7;

$week = intval($diff) + 1;

echo $week;

//Returns 2.

作为一个建议:

<?php

$ddate ="2012-10-18";

$duedt = explode("-",$ddate);

$date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]);

$week = (int)date('W', $date);

echo"Weeknummer:".$week;

?>

<?php

$ddate ="2012-10-18";

$date = new DateTime($ddate);

$we				

相关推荐

  • Spring部署设置openshift

    Springdeploymentsettingsopenshift我有一个问题让我抓狂了三天。我根据OpenShift帐户上的教程部署了spring-eap6-quickstart代码。我已配置调试选项,并且已将Eclipse工作区与OpehShift服务器同步-服务器上的一切工作正常,但在Eclipse中出现无法消除的错误。我有这个错误:cvc-complex-type.2.4.a:Invali…
    2025-04-161
  • 检查Java中正则表达式中模式的第n次出现

    CheckfornthoccurrenceofpatterninregularexpressioninJava本问题已经有最佳答案,请猛点这里访问。我想使用Java正则表达式检查输入字符串中特定模式的第n次出现。你能建议怎么做吗?这应该可以工作:MatchResultfindNthOccurance(intn,Patternp,CharSequencesrc){Matcherm=p.matcher…
    2025-04-161
  • 如何让 JTable 停留在已编辑的单元格上

    HowtohaveJTablestayingontheeditedcell如果有人编辑JTable的单元格内容并按Enter,则内容会被修改并且表格选择会移动到下一行。是否可以禁止JTable在单元格编辑后转到下一行?原因是我的程序使用ListSelectionListener在单元格选择上同步了其他一些小部件,并且我不想在编辑当前单元格后选择下一行。Enter的默认绑定是名为selectNext…
    2025-04-161
  • Weblogic 12c 部署

    Weblogic12cdeploy我正在尝试将我的应用程序从Tomcat迁移到Weblogic12.2.1.3.0。我能够毫无错误地部署应用程序,但我遇到了与持久性提供程序相关的运行时错误。这是堆栈跟踪:javax.validation.ValidationException:CalltoTraversableResolver.isReachable()threwanexceptionatorg.…
    2025-04-161
  • Resteasy Content-Type 默认值

    ResteasyContent-Typedefaults我正在使用Resteasy编写一个可以返回JSON和XML的应用程序,但可以选择默认为XML。这是我的方法:@GET@Path("/content")@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})publicStringcontentListRequestXm…
    2025-04-161
  • 代码不会停止运行,在 Java 中

    thecodedoesn'tstoprunning,inJava我正在用Java解决项目Euler中的问题10,即"Thesumoftheprimesbelow10is2+3+5+7=17.Findthesumofalltheprimesbelowtwomillion."我的代码是packageprojecteuler_1;importjava.math.BigInteger;importjava…
    2025-04-161
  • Out of memory java heap space

    Outofmemoryjavaheapspace我正在尝试将大量文件从服务器发送到多个客户端。当我尝试发送大小为700mb的文件时,它显示了"OutOfMemoryjavaheapspace"错误。我正在使用Netbeans7.1.2版本。我还在属性中尝试了VMoption。但仍然发生同样的错误。我认为阅读整个文件存在一些问题。下面的代码最多可用于300mb。请给我一些建议。提前致谢publicc…
    2025-04-161
  • Log4j 记录到共享日志文件

    Log4jLoggingtoaSharedLogFile有没有办法将log4j日志记录事件写入也被其他应用程序写入的日志文件。其他应用程序可以是非Java应用程序。有什么缺点?锁定问题?格式化?Log4j有一个SocketAppender,它将向服务发送事件,您可以自己实现或使用与Log4j捆绑的简单实现。它还支持syslogd和Windows事件日志,这对于尝试将日志输出与来自非Java应用程序…
    2025-04-161