比较时差

时间:2017-02-16 15:42:35

标签: php timestamp

我想比较发送消息之间的时间,以便我知道有人会多快响应。

message_sent是发送消息时的unix时间戳。 ID:0000000005是开头,ID:0000000006是对ID为0000000005的消息的响应。

根据这些数据:0000000006在1483021773发送了一条消息。原始问题是在0000000005 1483021687上询问的。所以反应时间是1483021773 - 1483021687.我应该如何处理这个问题,以便获得平均响应时间?

数据 Access SQL Reserved Words

2 个答案:

答案 0 :(得分:1)

假设响应时间由用户响应另一个用户的最后一条消息所花费的时间定义:

$response_times = array(); // array of response times
// let's define a variable to keep track of the person
// to which another person will respond. initially, variable will hold
// the first message 
$initiator = array_shift($messages);
// now iterator through messages
foreach ($messages as $message) {
    // if this message belongs to the initiator, just update the timestamp
    if ($message['from_user_id'] == $initiator['from_user_id']) {
        $initiator['message_sent'] = $message['message_sent'];
        continue; // and go to the next message
    }
    // otherwise, calculate the time difference and put it in response times
    array_push($response_times, $message['message_sent'] - $initiator['message_sent']);
    // and update the initiator
    $initiator = $message;
}
// finally, calculate average of response time
$avg_response_time = array_sum($response_times) / count($response_times);

答案 1 :(得分:0)

因为我不知道这里的确切代码是一些带有示例的sudo代码:

parser.parse_args

因此,如果阵列中有4个项目,响应时间分别为423,395,283,583,则平均响应时间为421,然后您可以转换为几分钟或几分钟。