Php 获取两个日期之间的秒数,并使用human_time_diff()显示它
我想计算两个日期之间的秒数,并在我的WooCommerce页面上显示购买的x秒、分钟、小时前文本 我有这个功能:Php 获取两个日期之间的秒数,并使用human_time_diff()显示它,php,date,time,strtotime,Php,Date,Time,Strtotime,我想计算两个日期之间的秒数,并在我的WooCommerce页面上显示购买的x秒、分钟、小时前文本 我有这个功能: $t_time = get_the_time( __( 'd/m/Y g:i:s', 'woocommerce' ), $order->ID ); /* $gmt_time = strtotime( $post->post_date_gmt ); */ $t_timestamp = strtotime ($t_time); date_default_timezo
$t_time = get_the_time( __( 'd/m/Y g:i:s', 'woocommerce' ), $order->ID );
/* $gmt_time = strtotime( $post->post_date_gmt ); */
$t_timestamp = strtotime ($t_time);
date_default_timezone_set('Europe/Budapest');
$ido = date('d/m/Y g:i:s');
$current_time = strtotime(date('d/m/Y g:i:s'));
//$current_time = strtotime(date('d/m/Y g:i:s'));
$time_diff = $current_time - $t_timestamp;
if ( $time_diff > 0 && $time_diff < 24*60*60 )
$h_time = sprintf( __( '%s ago', 'woocommerce' ), human_time_diff( $t_timestamp, $current_time ));
else
$h_time = get_the_time( $date_format, $order->ID );
}
$t_time=get_时间('d/m/Y g:i:s','woocommerce'),$order->ID);
/*$gmt\u time=strottime($post->post\u date\u gmt)*/
$t_timestamp=strottime($t_time);
日期默认时区设置(“欧洲/布达佩斯”);
$ido=日期('d/m/Y g:i:s');
$current_time=strottime(日期('d/m/Y g:i:s');
//$current_time=strottime(日期('d/m/Y g:i:s');
$time\U diff=$current\U time-$t\U timestamp;
如果($time_diff>0&&$time_diff<24*60*60)
$h_time=sprintf('s ago','woocommerce'),human_time_diff($t_timestamp,$current_time));
其他的
$h\u time=获取时间($date\u格式,$order->ID);
}
哪些产出:
HTIME:2014。九月十二日。时差:-2809
ido:12/09/2014 5:36:17
时间:2014年9月12日5:23:06
当前时间:1418099777
时间戳:1418102586
HTIME:2óra ago
格林尼治时间:
时间差:5891
ido:12/09/2014 5:36:17
时间:2014年9月12日3:58:06
当前时间:1418099777
时间戳:1418093886
我的问题是:当前时间怎么可能小于购买日期?在我看来,2014年9月12日5:36:17比5:23:06大 感谢您的帮助:)
我尝试了DateTime对象,但如果添加它,我的jQuery就会损坏,页面的某些部分无法加载。有一个未捕获的TypeError错误。我通过这个代码片段解决了这个问题
我认为这不是问题的原因,但
$current_time=strottime(日期('d/m/Y g:I:s')代码>可以重写$current_time=time()你应该得到同样的结果谢谢:)我已经试过了。但在这种情况下,我得到了时间差的数字,比如:时间差:-7565832,这是胡说八道