无法将日期字符串列表转换为时间戳并获取平均值

Cannot convert list of date strings to timestamp and get the average

我正在尝试但无法使其工作的是将以下日期字符串转换为时间戳格式,然后将此值插入 MySQL 中的时间戳字段后获得平均到达时间(第一个条目每天)和出发时间(每天最后一次进入)。 当我尝试在地方月份使用 strtotime 时,我得到了这一天。

11/1/2018 2:58:03 PM
11/1/2018 12:38:08 PM
11/1/2018 12:29:27 PM
11/1/2018 12:26:06 PM
11/1/2018 12:22:41 PM
11/1/2018 10:58:54 AM
10/31/2018 1:35:41 PM
10/31/2018 11:23:50 AM
10/31/2018 11:15:01 AM
10/31/2018 9:32:43 AM

我执行的转换代码如下:

$file_date = '11/30/2018 7:46:06 PM';
$file_date = str_replace('/', '-', $file_date);
$file_date = substr($file_date, 0, strpos($file_date, ' ', strpos($file_date, ' ')+1));
$file_date = strtotime($file_date);
echo $file_date.' ';
echo date('Y-m-d', $file_date).' ';

我在这里做错了什么?我得到的不是正确的值 1970-01-01

非常感谢您的回复。

希望对您有所帮助。它将字符串日期转换为 DateTime 对象并按照您的意愿格式化并转换为时间戳。

<?php
$file_date = '11/30/2018 7:46:06 PM';
$date = new DateTime($file_date);
$result = $date->format('m-d-Y');
// result is = 11-30-2018

$datetoTimeStamp =  $date->getTimestamp();

echo $datetoTimeStamp; // OUTPUT İS 1543607166

现在你可以在循环的帮助下找到所有这些值,并通过将总和除以值的数量来求平均值。