【发布时间】:2018-09-23 05:33:19
【问题描述】:
我正在使用 Bittrex REST API 查找不到十分钟前发生的交易:
https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-ETH
以下是从端点返回的一些交易时间戳:
2018-09-23T04:47:07.237
2018-09-23T04:47:02.797
虽然今天实际上是 2018 年 9 月 22 日我住的地方,但它显示了这些交易在未来发生。这些时间戳的时区是否不同?
$now = date('m/d/y g:i a');
$now = strtotime($now);
$ten_minutes_ago = strtotime('-10 minutes');
foreach ($buy_sell_bittrex_orders['result'] as $buy_sell_bittrex_order) {
$buy_sell_bittrex_order_timestamp = $buy_sell_bittrex_order['TimeStamp'];
echo "Ten Minutes ago: " . $ten_minutes_ago . "<br>";
echo "Buy sell timestamp: " . $buy_sell_bittrex_order_timestamp . "<br>";
echo "Now: " . $now . "<br><br>";
if ( strtotime($buy_sell_bittrex_order_timestamp) >= $ten_minutes_ago && strtotime($buy_sell_bittrex_order_timestamp) <= $now ) {
// Do something
}
}
当我使用上面的代码时,在 10 分钟前没有找到任何交易,尽管肯定有。不可能有未来发生的交易,所以这里有时间戳问题吗?
这是上面代码输出的示例:
Ten Minutes ago Bittrex: 1537679309
Buy sell timestamp: 1537704500
Now: 1537679940
在上面的示例中,“Buy sell timestamp”的值高于“now”,后者表示当前日期/时间。
如何转换交易时间戳以匹配我当前的时区?这似乎是问题所在,尽管我可能错了。谢谢!
【问题讨论】:
-
时间以 UTC 格式存储。