碳日期找出今天是星期四还是回去
Carbon dates find out if today is thursday or go back
我的一个脚本中有以下代码 运行,它运行良好,但感觉相当笨重和冗长。我觉得可能有更短的方法可以达到相同的结果。我的意思是不使用 shorthand if 语句。
我需要查明今天是不是星期四,如果不是,则使用前一个星期四作为日期。任何想法/想法都会很棒。
<?php
if (new Carbon('this thursday') > new Carbon()) {
$date = Carbon('this thursday');
} else {
$date = Carbon('last thursday');
}
?>
根据
http://carbon.nesbot.com/docs/#api-modifiers :
$date 将保存要显示的日期。
<?php
$today = new Carbon();
if($today->dayOfWeek == Carbon::THURSDAY)
$date = $today;
else
$date = new Carbon('last thursday');
?>
我的一个脚本中有以下代码 运行,它运行良好,但感觉相当笨重和冗长。我觉得可能有更短的方法可以达到相同的结果。我的意思是不使用 shorthand if 语句。
我需要查明今天是不是星期四,如果不是,则使用前一个星期四作为日期。任何想法/想法都会很棒。
<?php
if (new Carbon('this thursday') > new Carbon()) {
$date = Carbon('this thursday');
} else {
$date = Carbon('last thursday');
}
?>
根据 http://carbon.nesbot.com/docs/#api-modifiers :
$date 将保存要显示的日期。
<?php
$today = new Carbon();
if($today->dayOfWeek == Carbon::THURSDAY)
$date = $today;
else
$date = new Carbon('last thursday');
?>