将时间戳转换为当前时区

时间:2018-09-23 05:33:20

标签: php rest timestamp

我正在使用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”的值高。

如何转换交易时间戳以匹配当前时区?这似乎是问题,尽管我可能是错的。谢谢!

1 个答案:

答案 0 :(得分:0)

您应提供原始时区并将其转换为您的时区。

请参阅此Stackoverflow问题和答案。

Convert time and date from one time zone to another in PHP

祝你好运。