我想知道有没有人能帮我确定时区。在我的wordpress中,我将时区设置为纽约,当我在wordpress上预订时,预订被添加到woocommerce购物车中,时间完全改变,相差5小时。我想我已经在woocommerce wc格式函数中找到了要编辑的正确文件。php
/**
* Convert mysql datetime to PHP timestamp, forcing UTC. Wrapper for strtotime.
*
* Based on wcs_strtotime_dark_knight() from WC Subscriptions by Prospress.
*
* @since 3.0.0
*
* @param string $time_string
* @param int|null $from_timestamp
*
* @return int
*/
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;
}
或者这部分
function wc_timezone_string() {
// if site timezone string exists, return it
if ( $timezone = get_option( \'timezone_string\' ) ) {
return $timezone;
}
// get UTC offset, if it isn\'t set then return UTC
if ( 0 === ( $utc_offset = intval( get_option( \'gmt_offset\', 0 ) ) ) ) {
return \'UTC\';
}
// adjust UTC offset from hours to seconds
$utc_offset *= 3600;
// attempt to guess the timezone string from the UTC offset
if ( $timezone = timezone_name_from_abbr( \'\', $utc_offset ) ) {
return $timezone;
}
// last try, guess timezone string manually
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( (bool) date( \'I\' ) === (bool) $city[\'dst\'] && $city[\'timezone_id\'] && intval( $city[\'offset\'] ) === $utc_offset ) {
return $city[\'timezone_id\'];
}
}
}
// fallback to UTC
return \'UTC\';
}
SO网友:Ryan Mc Gonagle
Woocommerce代码日期
function wc_string_to_datetime( $time_string ) {
// Strings are defined in local WP timezone. Convert to UTC.
if ( 1 === preg_match( \'/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(Z|((-|\\+)\\d{2}:\\d{2}))$/\', $time_string, $date_bits ) ) {
$offset = ! empty( $date_bits[7] ) ? iso8601_timezone_to_offset( $date_bits[7] ) : wc_timezone_offset();
$timestamp = gmmktime( $date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1] ) - $offset;
} else {
$timestamp = wc_string_to_timestamp( get_gmt_from_date( gmdate( \'Y-m-d H:i:s\', wc_string_to_timestamp( $time_string ) ) ) );
}
$datetime = new WC_DateTime( "@{$timestamp}", new DateTimeZone( \'UTC\' ) );
// Set local timezone or offset.
if ( get_option( \'timezone_string\' ) ) {
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
} else {
$datetime->set_utc_offset( wc_timezone_offset() );
}
return $datetime;
}