\WP_Stager_Integration\Calendar::calculate_local_timestamp(string $date_string): int
\WP_Stager_Integration\Calendar::calculate_local_timestamp(string $date_string): intDescription
Calculates a timestamp in the current site's timezone for a date string. Takes the site's timezone setting into account.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$date_string | string | The date string (formatted as 'Y-m-d H:i:s') |
Returns:
int The Unix timestamp for the passed date string in the current site's timezone
Information
| File | class-calendar.php line 623 |
|---|---|
| See also |
|
Full Code
/**
* Calculates a timestamp in the current site's timezone for a date string. Takes the site's timezone setting into account.
*
* @param string $date_string The date string (formatted as <code>'Y-m-d H:i:s'</code>)
*
* @return int The Unix timestamp for the passed date string in the current site's timezone
*
* @see \WP_Stager_Integration\Calendar::calculate_offset_timestamp() for more information on the offset parameter.
*/
public static function calculate_local_timestamp( $date_string ) {
// Type casting
$date_string = (string) $date_string;
// Normalize date string
$date_string = (string) (\WP_Stager_Integration\Utility::normalize_datetime_string( $date_string ) ?: '');
// Bail if no date string
if ( '' === $date_string ) {
return 0;
}
// Instantiate DateTime object in the site's timezone
$date_time = new \DateTime( $date_string, wp_timezone() );
return $date_time->getTimestamp();
}💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration
🎁 Limited offer: Use code WELCOME26 to get your first month for free!

