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

Php 5/6位时间戳是什么格式?如何转换?,php,timestamp,ratchet,Php,Timestamp,Ratchet,使用Ratchet WebSocket,我试图显示发送消息的时间戳。Iconsole.log(e)在onmessage回调中,我得到一个对象: { //... rest of the keys timeStamp: 353443 } 考虑到我在13:48发的,我觉得它看起来很奇怪。奇怪的是,之前,我在最后一个小时内发送了一个请求,它返回了一个5位数的时间戳,这使得我的研究更加困难 我试着在Ratchet文档中查找字段,但找不到任何内容。通过在线转换,我立即尝试查看它是否是UNI

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

{
    //... rest of the keys
    timeStamp: 353443
}
考虑到我在13:48发的,我觉得它看起来很奇怪。奇怪的是,之前,我在最后一个小时内发送了一个请求,它返回了一个5位数的时间戳,这使得我的研究更加困难

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

1970年1月1日:时间

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

目前我有(在我的jQuery中):

但是它返回1月1日的东西

我试过两次:

2018年9月6日星期四14:03:(秒数约为13)
2018年9月6日星期四14:19:24

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

0123384
2195683

(显示没有空格)

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

我试着比较这两个,除了分钟和秒之外,其他都应该是一样的,但是只有两列匹配

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

周四可能是3或4,这取决于编码器是否将周日或周一设置为0

从逻辑上讲,6只应等于6

如果1月=0,9月可能是8日

2018年可能是18年

14可能是2,如果12小时,且标志设置为am/pm

下面是我的Chat.php类:

<?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();
        }
    }

多亏@Michel的评论,我才设法弄明白

我去了timeago jquery插件项目页面,它显示它来自连接,正如Michel所说

它从服务器连接时间到我所做的测试:

在9:08:00启动脚本

用户1在9:09:00连接

用户2在9:12:00连接

9:19:00的消息1

9:20:00的消息2

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

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

将毫秒转换为分钟时,第一个值为10分钟,后一个值为11分钟

看起来是ms,但由于使用timeago,它从服务器启动开始,而不是1970年1月1日


文档中应该明确指出的一些问题,但这是一个单独的问题。

我试图提供几分钟的帮助,但我能找到的所有有意义的方法是使用微秒(
u
),但结果是
15:16
,我想这不是您所期望的。这对我来说毫无意义。特别是
0 1 2 3 3 8 4
问题中的前导零:您是每次发送消息时都开始新的聊天,还是对所有四条消息都使用相同的连接,即您是否保持聊天室打开?我认为这是第一次连接/消息发送与其他消息之间的时间差(毫秒)。看一看。它使用
jquery.timeago.js
设置收到的消息时间。所以,试着在某处注册连接时间,并将其与您收到的时间戳进行比较。@Michel请参阅答案:)
<?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();
        }
    }
<?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();