【问题标题】:Convert TimeStamp to current timezone将时间戳转换为当前时区
【发布时间】: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 格式存储。

标签: php rest timestamp


【解决方案1】:

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

查看这个 Stackoverflow 问题和答案。

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

祝你好运。

【讨论】:

  • 谢谢,你知道它在哪个时区吗?其余的 api 时间戳是
  • 您应该提供一些实际代码。仅链接的答案不是很好。如果您觉得这个问题与另一个问题重复,我建议您在获得更多声望点时将其标记为另一个问题的重复,或者直接将其写为问题下方的评论。
  • 注明。谢谢@Mike
猜你喜欢
  • 1970-01-01
  • 2011-05-10
  • 2019-11-12
  • 1970-01-01
  • 2016-03-04
  • 1970-01-01
  • 1970-01-01
  • 2016-07-09
  • 2013-05-20
相关资源
最近更新 更多