date_create_immutable_from_format example

// If this is a comment feed, check those objects too.         if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
            // Extract the comment modified times from the comments.             $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );

            // Add the comment times to the post times for comparison.             $modified_times = array_merge( $modified_times$comment_times );
        }

        // Determine the maximum modified time.         $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times )$utc );
    }

    if ( false === $datetime ) {
        // Fall back to last time any post was modified or published.         $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' )$utc );
    }

    if ( false !== $datetime ) {
        $max_modified_time = $datetime->format( $format );
    }

    
$time     = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt;
        $timezone = new DateTimeZone( 'UTC' );
    } else {
        $time     = ( 'modified' === $field ) ? $post->post_modified : $post->post_date;
        $timezone = $wp_timezone;
    }

    if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
        return false;
    }

    $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time$timezone );

    if ( false === $datetime ) {
        return false;
    }

    return $datetime->setTimezone( $wp_timezone );
}

/** * Retrieves post published or modified time as a Unix timestamp. * * Note that this function returns a true Unix timestamp, not summed with timezone offset * like older WP functions. * * @since 5.3.0 * * @param int|WP_Post $post Optional. Post ID or post object. Default is global `$post` object. * @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. * Default 'date'. * @return int|false Unix timestamp on success, false on failure. */
Home | Imprint | This part of the site doesn't use cookies.