我想計算兩個日期之間的秒數,並在我的WooCommerce頁面上顯示購買的x秒,分鐘,小時前的文本。獲取兩個日期之間的秒數並使用human_time_diff()顯示它
我有這樣的功能:
$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);
}
,其輸出:
HTIME:2014年szeptember 12.
time_diff:-2809
氧酶:2014年12月9日5點36分17秒
t_time:2014年12月9日5時23分06秒
CURRENT_TIME:1418099777
t_timestamp:1418102586
HTIME:2 ORA以前
gmt_time:
time_diff:5891
IDO:2014年12月9日五時36分17秒
t_time:2014年12月9日3時58分06秒
CURRENT_TIME: 1418099777
t_timestamp:1418093886
我的問題是:當前時間如何小於購買日期?在我看來,12/09/2014 5:36:17比5:23:06更大。
每一個幫助表示讚賞:)
我已經試過DateTime對象,但如果我添加它,我的jQuery的損壞,以及頁面的某些部分不加載。有一個Uncaught TypeError錯誤。
我不認爲這是導致該問題,但'$ CURRENT_TIME =的strtotime(日期( '/月/ Y G:我:S'));'可以改寫'$ CURRENT_TIME = time();'你應該得到相同的結果 – 2014-09-12 15:42:49
謝謝:)我已經試過了。但在這種情況下,我得到了time_diff數字,如:time_diff:-7565832,這是無稽之談 – beamkiller 2014-09-12 15:47:36