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

I want to find the timestamp for the most recent 8am encountered. (weekdays only)

For example if its Friday at 3pm I want the timestamp for 8am.

I can do that simply enough, but what about if it is Saturday at 2am.

Also if it is Monday at 6am I want to find Friday at 8am still.

Tried the following:

$timestamp = strtotime(date('Y-m-d') . '08:00:00');

But clearly that only accounts for the current day.

This should do it:

// 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' );
}