PHP 开关:计算日期
PHP switch: calculate dates
我做了这个切换,但我不知道最后一步(?? 和注释)。
如果有人可以帮助我,非常感谢!
<?
$nuDatumTijd = date("Y-m-d H:i:s");
$nuUur = date("H");
switch(true)
{
case $nuUur > 8 && $nuUur < 13:
$aantSecErbij = ??; // number of seconds untill the first next 13:00
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
case $nuUur > 12 && $nuUur < 18:
$aantSecErbij = ??; // number of seconds untill the first next 19:00
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
case $nuUur > 17 && $nuUur < 22:
$aantSecErbij = ??; // number of seconds untill the first next 9:00 (so that is the next day)
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
}
?>
switch-case 也可以这样使用,没问题。
$aantSecErbij = ??; // number of seconds untill the first next 13:00
如果这表示到今天下午 1 点的秒数,那么以下内容将为您提供今天下午 1 点的时间戳。
$now = getdate();
$time1pm = mktime(13, 0, 0, $now['mon'], $now['mday'], $now['year']);
如果它表示从现在到今天下午 1 点之间的秒数,那么您需要减去当前时间戳。
$now = getdate();
$diff1pm = mktime(13, 0, 0, $now['mon'], $now['mday'], $now['year']) - time();
.
$aantSecErbij = ??; // number of seconds untill the first next 9:00 (so that is the next day)
对于第二天,您可以将日部分加 1,而不必担心月末。 PHP 会为您找出合适的日期。
$now = getdate();
$tomorrow9am = mktime(9, 0, 0, $now['mon'], $now['mday'] + 1, $now['year']);
我现在已经用这种方法修复了它,感谢您的输入:
$nuUur = date("H");
if ($nuUur > 8 && $nuUur < 13)
{
$weerOp = strtotime('today 13:00');
$weerOpNetjes = date('Y-m-d H:i:s', $weerOp);
echo $weerOpNetjes;
}
elseif ($nuUur > 12 && $nuUur < 18)
{
$weerOp = strtotime('today 19:00');
$weerOpNetjes = date('H:i', $weerOp);
echo $weerOpNetjes;
}
elseif ($nuUur > 17 && $nuUur < 22)
{
$weerOp = strtotime('tomorrow 9:00');
$weerOpNetjes = date('H:i', $weerOp);
echo $weerOpNetjes;
}
我做了这个切换,但我不知道最后一步(?? 和注释)。 如果有人可以帮助我,非常感谢!
<?
$nuDatumTijd = date("Y-m-d H:i:s");
$nuUur = date("H");
switch(true)
{
case $nuUur > 8 && $nuUur < 13:
$aantSecErbij = ??; // number of seconds untill the first next 13:00
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
case $nuUur > 12 && $nuUur < 18:
$aantSecErbij = ??; // number of seconds untill the first next 19:00
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
case $nuUur > 17 && $nuUur < 22:
$aantSecErbij = ??; // number of seconds untill the first next 9:00 (so that is the next day)
$weerOp = date($nuDatumTijd,$aantSecErbij);
echo $weerOp;
break;
}
?>
switch-case 也可以这样使用,没问题。
$aantSecErbij = ??; // number of seconds untill the first next 13:00
如果这表示到今天下午 1 点的秒数,那么以下内容将为您提供今天下午 1 点的时间戳。
$now = getdate();
$time1pm = mktime(13, 0, 0, $now['mon'], $now['mday'], $now['year']);
如果它表示从现在到今天下午 1 点之间的秒数,那么您需要减去当前时间戳。
$now = getdate();
$diff1pm = mktime(13, 0, 0, $now['mon'], $now['mday'], $now['year']) - time();
.
$aantSecErbij = ??; // number of seconds untill the first next 9:00 (so that is the next day)
对于第二天,您可以将日部分加 1,而不必担心月末。 PHP 会为您找出合适的日期。
$now = getdate();
$tomorrow9am = mktime(9, 0, 0, $now['mon'], $now['mday'] + 1, $now['year']);
我现在已经用这种方法修复了它,感谢您的输入:
$nuUur = date("H");
if ($nuUur > 8 && $nuUur < 13)
{
$weerOp = strtotime('today 13:00');
$weerOpNetjes = date('Y-m-d H:i:s', $weerOp);
echo $weerOpNetjes;
}
elseif ($nuUur > 12 && $nuUur < 18)
{
$weerOp = strtotime('today 19:00');
$weerOpNetjes = date('H:i', $weerOp);
echo $weerOpNetjes;
}
elseif ($nuUur > 17 && $nuUur < 22)
{
$weerOp = strtotime('tomorrow 9:00');
$weerOpNetjes = date('H:i', $weerOp);
echo $weerOpNetjes;
}