第一次我用PHP将日期转换为周数(01到53),现在我没有';I don’我不知道如何将周数设置为周的第一天
下面是一个简单的 日期到周\年数和现在。如何获取周号的开始日期和结束日期第一次我用PHP将日期转换为周数(01到53),现在我没有';I don’我不知道如何将周数设置为周的第一天,php,date,Php,Date,下面是一个简单的 日期到周\年数和现在。如何获取周号的开始日期和结束日期 $date_string = "2012-12-30"; echo "Weeknummer: " . date("W", strtotime($date_string)); 您可以使用以下选项: <?php $date_string = "2012-12-30"; $weekNumber = date("W", strtotime($date_string)); echo "Weeknum
$date_string = "2012-12-30";
echo "Weeknummer: " . date("W", strtotime($date_string));
您可以使用以下选项:
<?php
$date_string = "2012-12-30";
$weekNumber = date("W", strtotime($date_string));
echo "Weeknummer: ".$weekNumber;
echo '</br>';
// get the year
$year = date("Y", strtotime($date_string));
// set the date string for the week number
$dateWeek = $year.'-W'.$weekNumber;
// increase the weekNumber to the next
$weekNumber = intval($weekNumber);
$weekNumber += 1;
// if it is lower than 10 add preceeding 0
if($weekNumber < 10) $weekNumber = '0'.$weekNumber;
// set the date string for the next week number
$dateWeekNext = $year.'-W'.$weekNumber;
echo '</br>';
// get the first day of the week
echo date('Y-m-d', strtotime($dateWeek));
echo '</br>';
// get the day before the first day of the next week
echo date('Y-m-d', strtotime($dateWeekNext . ' -1 day'));
?>
您可以使用以下选项:
<?php
$date_string = "2012-12-30";
$weekNumber = date("W", strtotime($date_string));
echo "Weeknummer: ".$weekNumber;
echo '</br>';
// get the year
$year = date("Y", strtotime($date_string));
// set the date string for the week number
$dateWeek = $year.'-W'.$weekNumber;
// increase the weekNumber to the next
$weekNumber = intval($weekNumber);
$weekNumber += 1;
// if it is lower than 10 add preceeding 0
if($weekNumber < 10) $weekNumber = '0'.$weekNumber;
// set the date string for the next week number
$dateWeekNext = $year.'-W'.$weekNumber;
echo '</br>';
// get the first day of the week
echo date('Y-m-d', strtotime($dateWeek));
echo '</br>';
// get the day before the first day of the next week
echo date('Y-m-d', strtotime($dateWeekNext . ' -1 day'));
?>
有很多方法,这里有一种。
我使用日期的“N”来确定所选日期是哪一天,并使用strotimes理解简单文本的方式来查找上一个或下一个星期一/星期天
$date_string = "2018-01-27";
$w =date("W", strtotime($date_string));
$N =date("N", strtotime($date_string));
If($N == 1){ // if monday
$monday = $date_string;
$sunday = date("Y-m-d", strtotime("next Sunday $date_string"));
}Elseif($N ==7){ // if sunday
$monday = date("Y-m-d", strtotime("previous Monday $date_string"));
$sunday = $date_string;
}Else{// any other weekday
$monday = date("Y-m-d", strtotime("previous Monday $date_string"));
$sunday = date("Y-m-d", strtotime("next Sunday $date_string"));
}
echo "Weeknummer: $w.\nMonday: $monday.\nSunday: $sunday.";
输出:
周数:52。周一:2012-12-24。
星期日:2012年12月30日
有很多方法,这里有一种。
我使用日期的“N”来确定所选日期是哪一天,并使用strotimes理解简单文本的方式来查找上一个或下一个星期一/星期天
$date_string = "2018-01-27";
$w =date("W", strtotime($date_string));
$N =date("N", strtotime($date_string));
If($N == 1){ // if monday
$monday = $date_string;
$sunday = date("Y-m-d", strtotime("next Sunday $date_string"));
}Elseif($N ==7){ // if sunday
$monday = date("Y-m-d", strtotime("previous Monday $date_string"));
$sunday = $date_string;
}Else{// any other weekday
$monday = date("Y-m-d", strtotime("previous Monday $date_string"));
$sunday = date("Y-m-d", strtotime("next Sunday $date_string"));
}
echo "Weeknummer: $w.\nMonday: $monday.\nSunday: $sunday.";
输出:
周数:52。周一:2012-12-24。
星期日:2012年12月30日
当然可以,先生,但我没有尝试,因为我正在编写其他内容。是的,谢谢你支持我。是的,当然,先生,但我没有尝试,因为我正在制作其他内容。是的,谢谢你支持我。