我输入了时区America/Lima (设置>常规)
但是current_time(\'timestamp\') 显示其他日期时间。
例如:现在利马是2015-10-25 12:01:00,但当前时间(“时间戳”)显示:2016-10-24 19:01:05
我做错什么了?
PD:wp\\U选项中的我的变量是:gmt_offset 为空,timezone_string 是美国/利马
当做
我输入了时区America/Lima (设置>常规)
但是current_time(\'timestamp\') 显示其他日期时间。
例如:现在利马是2015-10-25 12:01:00,但当前时间(“时间戳”)显示:2016-10-24 19:01:05
我做错什么了?
PD:wp\\U选项中的我的变量是:gmt_offset 为空,timezone_string 是美国/利马
当做
尝试传入第二个参数,告诉它使用GMT偏移量。
current_time( \'timestamp\', true );
设置DateTimeZone
的DateTime
对象以确保区域正确。
$d = date( \'c\', time() );
echo $d . \'<br /><br />\';
$timezone = get_option(\'timezone_string\');
if( empty($timezone) ) $timezone = \'America/Lima\';
$t = new DateTime($d);
$t->setTimezone(new DateTimeZone( $timezone ));
echo "\\tTime in ${timezone}\\t" . $t->format( \'c\' );
// 2016-10-25T06:10:16+00:00
// Time in America/Lima 2016-10-25T01:10:16-05:00
凉的谢谢你的回答,这对我帮助很大。
我试图得到我的未付订单,在Woocommerce中一段时间后自动取消它们。它不起作用,因为默认情况下它使用current\\u time(“timestamp”)。
woocommerce/includes/wc-order-functions.php
function wc_cancel_unpaid_orders() {
global $wpdb;
$held_duration = get_option( \'woocommerce_hold_stock_minutes\' );
if ( $held_duration < 1 || get_option( \'woocommerce_manage_stock\' ) != \'yes\' )
return;
$date = date( "Y-m-d H:i:s", strtotime( \'-\' . absint( $held_duration ) . \' MINUTES\', current_time( \'timestamp\' ) ) );
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
WHERE posts.post_type IN (\'" . implode( "\',\'", wc_get_order_types() ) . "\')
AND posts.post_status = \'wc-pending\'
AND posts.post_modified < %s
", $date ) );
if ( $unpaid_orders ) {
foreach ( $unpaid_orders as $unpaid_order ) {
$order = wc_get_order( $unpaid_order );
if ( apply_filters( \'woocommerce_cancel_unpaid_order\', \'checkout\' === get_post_meta( $unpaid_order, \'_created_via\', true ), $order ) ) {
$order->update_status( \'cancelled\', __( \'Unpaid order cancelled - time limit reached.\', \'woocommerce\' ) );
}
}
}
}
那么我无法更改此代码。这始终使用current\\u时间(“timestamp”)。如果我保存订单,他的日期是2016-10-25 11:20:11am 但是current\\u time(“timestamp”)表示2016-10-25 06:20:11.
我做错什么了?
PD:wp\\u选项中的我的变量是:gmt\\u offset为空,timezone\\u string为America/Lima
当做
听起来好像您有一些代码将PHP中的默认时区更改为您的时区,而不是将其单独作为UTC时区。
基本上,您的PHP。INI文件中有美制/利马(当它应该作为UTC单独存在时),或者某个东西正在用美制/利马调用date\\u default\\u timezone\\u set()。
在这种情况下,正常的PHP time()和date()函数将返回本地时区(America/Lima)中的时间,然后WordPress将通过再次应用时区更改来“过度更正”它。
要解决这个问题,您需要查找调用date\\u default\\u timezone\\u set的任何其他代码并将其禁用。WordPress希望PHP中的时区为UTC,并自行应用更正,而不是让PHP应用更正。这主要是因为遗留的原因。PHP 4没有很好的时区处理,因此许多现有代码都希望WordPress能够以这种方式处理它。
current\\u time(“timestamp”)是否存在问题?我试图获取当前的\\u时间(“时间戳”),而不是给我current time: Jun 26 2013 14:30 它给了我:Jun 26 2013 21:30 我试着检查秒数,它给了我:1372282238 这对于给定的时间是正确的,但对于real current time. 发生了什么事?