将日期转换为东部时间戳
Converting date to eastern time timestamp
我很困惑。我正在使用需要基于东部时间的 UNIX 时间戳的 API。它的格式类似于 Date(1496332800000)
而 UNIX 时间戳类似于 1496332800000
。我不确定如何将 2017-08-29
之类的简单日期转换为 1496332800000
之类的格式
它期望 eastern time
而不是 UTC
时间。我不确定如何转换它
首先,了解时间戳没有时区很重要。时间戳代表一个特定的时刻;例如,我可以说 "what is the timestamp right now?" 就在我输入这个的那一刻:
1514516921
无论你在世界的哪个角落,或者我在世界的哪个角落,或者任何阅读本文的人都在。这个时间戳代表我们所有人的同一时刻。对我来说,在我的时区,它是 7:08pm 因为我住在美国太平洋时区。对于住在纽约的人来说,这个时刻(时间戳)发生在 10:08pm。对于生活在欧洲的人来说,一天中的时间非常不同。但对我们所有人来说,那个时间戳代表了我在键盘上打字的那一刻。
所以,如果你的问题是
how do I convert a date to a unix timestamp
在php中,你通常使用strtotime
http://php.net/manual/en/function.strtotime.php一些例子:
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
我的理解是你想将 2017-08-29 转换为 1503964800。
如果是上述情况,则使用碳。以下是带有输出的代码
代码:
Carbon::parse('2017-08-29')->时间戳;
输出:
1503964800
我很困惑。我正在使用需要基于东部时间的 UNIX 时间戳的 API。它的格式类似于 Date(1496332800000)
而 UNIX 时间戳类似于 1496332800000
。我不确定如何将 2017-08-29
之类的简单日期转换为 1496332800000
它期望 eastern time
而不是 UTC
时间。我不确定如何转换它
首先,了解时间戳没有时区很重要。时间戳代表一个特定的时刻;例如,我可以说 "what is the timestamp right now?" 就在我输入这个的那一刻:
1514516921
无论你在世界的哪个角落,或者我在世界的哪个角落,或者任何阅读本文的人都在。这个时间戳代表我们所有人的同一时刻。对我来说,在我的时区,它是 7:08pm 因为我住在美国太平洋时区。对于住在纽约的人来说,这个时刻(时间戳)发生在 10:08pm。对于生活在欧洲的人来说,一天中的时间非常不同。但对我们所有人来说,那个时间戳代表了我在键盘上打字的那一刻。
所以,如果你的问题是
how do I convert a date to a unix timestamp
在php中,你通常使用strtotime
http://php.net/manual/en/function.strtotime.php一些例子:
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
我的理解是你想将 2017-08-29 转换为 1503964800。
如果是上述情况,则使用碳。以下是带有输出的代码
代码: Carbon::parse('2017-08-29')->时间戳; 输出: 1503964800