【问题标题】:PHP: strtotime revered return strange date?PHP:strtotime 崇敬返回奇怪的日期?
【发布时间】:2015-08-11 17:17:06
【问题描述】:

我正在使用 php strtotime 和 mysql datetime 对某个日期进行简单的倒计时。

我也是用jQuery来倒计时的。

我的 jquery strtotime 时间是这样的:1443661380000

如果我在没有任何 php 的情况下运行我的 jquery 倒计时,它工作得很好并且可以正常倒计时。

但是,当我像这样使用 mysql datetime 和 php strtotime 时:$long = strtotime("$fes_events_date"); 我的 jquery 倒计时停止工作。

所以我尝试反转 jquery strtotime 1443661380000,这样我可以看到它的样子,以防我在我的 php strtotime 中遗漏一些东西。

所以我这样做了:

    $hin = date("Y-m-d H:i:s", 1443661380000);
echo $hin;

它的输出有点奇怪,如下所示:

47717-10-22 18:00:00

所以我的问题是,如何使用 php strtotime 转换我的 datetime mysql,以便获得相同类型的输出以使我的 jquery 倒计时工作?

任何帮助将不胜感激。

【问题讨论】:

  • 时间戳以毫秒为单位。您需要将其转换为秒才能使用 strtotime()

标签: javascript php jquery mysql datetime


【解决方案1】:

尝试改变,

$hin = date("Y-m-d H:i:s", 1443661380000);

$mil=1443661380000;
$seconds = $mil / 1000;
$hin = date("Y-m-d H:i:s", $seconds);

【讨论】:

    【解决方案2】:

    unix 时间戳,date 函数的第二个参数,是自 1970 年 1 月 1 日以来的秒数。

    由于历史迷雾中的原因,javascript 时间戳是自 unix 纪元以来的毫秒数。 PHP strToTime 函数无法识别这一点,也无法发挥它的魔力。您需要手动将毫秒转换为秒。

    $hin = date("Y-m-d H:i:s", (1443661380000/1000));
    echo $hin;
    

    【讨论】:

      【解决方案3】:

      知道测量UNIX / Epoch Time 通常以两种方式之一完成,以秒为单位,或自January, 1 1970 以来以毫秒为单位。

      在我看来,您的时间以毫秒为单位,而您尝试使用的函数将其转换为以秒为单位,因此您相差 1000 倍。

      尝试将时间减 1000,然后将其传递到转换器。

      1000ms/1000 = 1s
      1443661380000ms / 1000 = 144366138s
      
      144366138s -> Date -> GMT: Thu, 01 Oct 2015 01:03:00
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-11
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 2015-01-03
        • 1970-01-01
        • 2018-05-11
        • 2023-03-03
        相关资源
        最近更新 更多