wc_string_to_timestamp( string $time_string, int|null $from_timestamp = null )

Convert mysql datetime to PHP timestamp, forcing UTC. Wrapper for strtotime.


Description Description

Based on wcs_strtotime_dark_knight() from WC Subscriptions by Prospress.


Parameters Parameters

$time_string

(Required) Time string.

$from_timestamp

(Optional) Timestamp to convert from.

Default value: null


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/wc-formatting-functions.php

function wc_string_to_timestamp( $time_string, $from_timestamp = null ) {
	$original_timezone = date_default_timezone_get();

	// @codingStandardsIgnoreStart
	date_default_timezone_set( 'UTC' );

	if ( null === $from_timestamp ) {
		$next_timestamp = strtotime( $time_string );
	} else {
		$next_timestamp = strtotime( $time_string, $from_timestamp );
	}

	date_default_timezone_set( $original_timezone );
	// @codingStandardsIgnoreEnd

	return $next_timestamp;
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.