找到上次8点遇到的时间戳?

And*_*ait 3 php time date

我想找到最近8点遇到的时间戳.(仅限工作日)

例如,如果星期五下午3点我想要时间戳为早上8点.

我可以做到这一点,但是如果它是星期六凌晨2点呢.

如果是星期一早上6点,我想在星期五早上8点找到.

尝试以下方法:

$timestamp = strtotime(date('Y-m-d') . '08:00:00');
Run Code Online (Sandbox Code Playgroud)

但显然只能说明当天.

JJJ*_*JJJ 5

这应该这样做:

// Choose today if it's past 08:00 and it's not a weekend
if( date( 'G' ) >= 8 && date( 'N' ) <= 5 ) {
    $timestamp = strtotime( date( 'Y-m-d' ).' 08:00' );
}
else {
    $timestamp = strtotime( 'last weekday 08:00' );
}
Run Code Online (Sandbox Code Playgroud)