我试图在这个周末用PHP。
我按代码获取当前日期:
$start_date = date("Y-m-d H:i:s", time());
我如何才能获得当前的周末取决于当前的日期?谢谢!
答案 0 :(得分:16)
PHP strtotime函数很神奇,大多数人都不知道但是你可以用这个函数做很多事情。
$start_date = date("Y-m-d H:i:s", strtotime('next Saturday'));
答案 1 :(得分:4)
$sat = strtotime('saturday');
答案 2 :(得分:1)
$start_date = date("Y-m-d H:i:s", strtotime('Saturday'));
答案 3 :(得分:0)
试试这个:
<?php
$time = mktime();
$found = false;
while(!$found) {
$d = date('N', $time);
if($d == 6 || $d == 7) {
$found = true;
$weekend = date('d/m/Y G:i:s', $time);
}
$time += 86400;
}
echo("Weekend begins on: $weekend");
?>
答案 4 :(得分:0)
我对“周末”的定义是下周五,办公时间结束直到周日结束。 在PHP中,这将是
$weekend = new DatePeriod(
new DateTime('next Friday 18:00'),
DateInterval::createFromDateString('+1 hour'),
new DateTime('next Friday +2 day 23:59'));
foreach($weekend as $hours) {
echo $hours->format( "l Y-m-d H:i:s\n" );
}
答案 5 :(得分:0)
第一个周末计算
if(date('w')==6){// Today is Saturday | Bugün Cumartesi ise
$wknd=date("Y-md-").'-'.date("Y-m-d", strtotime('next Sunday'));
}if(date('w')==0){// Today is Sunday | Bugün Pazar ise
$wknd=date("Y-m-d");
}else{ // On weekdays | Hafta içi ise
$wknd=date("Y-m-d", strtotime('next Saturday')).'-'.date("Ymd", strtotime('next Sunday'));
}
echo $wknd;