5/6 位时间戳是什么格式,如何转换?

What Format is a 5/6 Digit TimeStamp and how do I convert it?

使用 Ratchet WebSocket,我正在尝试显示已发送消息的时间戳。我 console.log(e) 在 onmessage 回调中得到一个对象:

{
    //... rest of the keys
    timeStamp: 353443
}

考虑到我在 13:48 发送的,我觉得它看起来很奇怪。奇怪的是,之前,我在最后一个小时内发送了一个请求,它 return 编辑了一个 5 位数的时间戳,这让我的研究变得更加困难。

我尝试在 Ratchet 文档中查找该字段,但找不到任何内容。我立即尝试通过在线转换它来查看它是否是 UNIX 时间戳,但所有值 return

1 Jan 1970 some:time

如何将 returned 时间戳转换为 d/m/y H:i?我找不到任何关于它可能是什么格式或如何转换的信息。

目前我有(在我的jQuery):

new Date(data.timeStamp*1000)

但它 return 是 1 月 1 日的事情。

我试过两次:

Thursday 6th September 2018 14:03:(seconds was roughly 13)
Thursday 6th September 2018 14:19:24

这产生了这些时间戳(分别):

0 1 2 3 3 8 4
2 1 9 5 6 8 3

(显示没有空格)

(注意:前导 0 不在输出中 - 仅用于列比较)

我尝试比较两者,除了分钟和秒之外的所有内容都应该相同,但是 - 只有两列匹配。

我怎么可能认为它可能是这样的(但事实证明它不能基于结果的不同程度):

Thursday has the potential to be 3 or 4 depending if the coder has set Sunday or Monday to 0

6th should logically only equate to 6

Sept could be 8 if jan = 0

2018 could be 18

14 could be 2 if 12 hour with a flag setting am/pm

这是我的 Chat.php class:

<?php
    namespace App;

    use Ratchet\MessageComponentInterface;
    use Ratchet\ConnectionInterface;

    class Chat implements MessageComponentInterface
    {
        protected $clients;

        public function __construct()
        {
            $this->clients = new \SplObjectStorage;
        }

        public function onOpen(ConnectionInterface $conn)
        {
            $this->clients->attach($conn); # store new con to send msg later
            echo 'New Connection! '. $conn->resourceId ."\n";
        }

        public function onMessage(ConnectionInterface $from, $msg)
        {
            $numRecv = count($this->clients) - 1;

            echo sprintf(
                'Connection %d sending message "%s" to %d other connection%s'. "\n",
                $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's'
            );

            foreach ($this->clients as $client)
            {
                if ($from !== $client) {
                    $client->send($msg); # sender is not receiver, send to each client connected
                }
            }
        }

        public function onClose(ConnectionInterface $conn)
        {
            $this->clients->detach($conn); # con is closed, rm it, can no longer send it a msg
            echo 'Connection '. $conn->resourceId .' has disconnected'. "\n";
        }

        public function onError(ConnectionInterface $conn, \Exception $e)
        {
            echo 'An error has occurred: '. $e->getMessage() ."\n";
            $conn->close();
        }
    }

和我的聊天-server.php

<?php
    use Ratchet\Server\IoServer;
    use Ratchet\Http\HttpServer;
    use Ratchet\WebSocket\WsServer;
    use App\Chat;

    require dirname(__DIR__). '/vendor/autoload.php';

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Chat()
            )
        ),
        8080
    );

    $server->run();

link 到项目:http://socketo.me/

我对这些数字进行了一些计算:

2195683 - 123384 = 2072299

difference between 14:03:13 and 14:19:24 is 16 minutes and 11 seconds

不知何故 16 分 11 秒必须大致等于 2072299

大更新

好的,我比较了 4 个新日期:

Thu 06 Sept 2018 15:26:40

Thu 06 Sept 2018 15:31:03

Thu 06 Sept 2018 16:26:40

Thu 06 Sept 2018 16:31:03

我有理论认为时间可能是从某个时间开始的,所以 26:40 将始终与从小时开始的 X 微秒相同。以下是结果:

Thu 06 Sept 2018 15:26:40
40491

Thu 06 Sept 2018 15:31:03
303762

Thu 06 Sept 2018 16:26:40
1351367

Thu 06 Sept 2018 16:31:03
1614388

我决定计算出它们之间的区别,它们相隔 4 分 23 秒,但是这样做:

303762 - 40491 = 263271

1614388 - 1351367 = 263021

相差 250。

我还比较了两者相隔一个小时的时间:

1351367 - 40491 = 1310876

1614388 - 303762 = 1310626

又相差 250。

所以没有多少时间是相同的,这让我怀疑它确实是从某个时间而不是现在开始的。

然后我决定每隔 1 秒执行一次:

21 = 2232366

22 = 2233365

23 = 2234333

前 4 位数字如预期的那样递增(以 1 秒为单位),但随后变为 66、65、33 ... 这是如何生成的?

谢谢,

感谢@Michel 的评论,我设法弄明白了。

我去timeago jquery插件项目页面,它显示它是从连接中走出来的,就像米歇尔说的。

它从服务器连接时间开始 - 测试我做了:

booted the script at 9:08:00

user 1 connect at 9:09:00

user 2 connect at 9:12:00

message 1 at 9:19:00

message 2 at 9:20:00

消息 1 返回的时间戳为:653905

消息 2 返回的时间戳为:713738

将毫秒转换为分钟时,第一个为 10 分钟,第二个为 11 分钟。

看起来是以毫秒为单位,但由于使用了 timeago,它从服务器启动开始 - 而不是 1970 年 1 月 1 日。

文档中绝对应该注意的事项,但这是一个单独的问题。