PHP strtotime 转换不适用于某些日期时间

PHP strtotime conversion not working for some datetimes

我正在尝试对 Web 服务结果集中的日期时间条目(从不为空)执行 strtotime。

在循环和转换时,我发现很多都无法使用 strtotime 进行转换。问题是什么?有效和无效的格式之间没有区别。

1431109502 - 08-05-2015 13:25:02
- 06-15-2015 12:05:32 -- Didn't work (any that start with - didn't convert)
- 06-25-2015 11:30:30
- 06-15-2015 10:58:56
- 06-27-2015 20:33:31
- 06-28-2015 00:13:37
1431054141 - 07-05-2015 22:02:21
- 07-17-2015 07:23:57
- 07-22-2015 02:30:24
1431090998 - 08-05-2015 08:16:38
1433774646 - 08-06-2015 09:44:06

编辑:这是我用来尝试获得 100% 转化的一些代码。

$t = date_create_from_Format( 'd-m-Y H:i:s', trim($arrCurrentAlarms[$i]["DateTime"]) );
$sqldt = $t->format('Y-m-d H:i:s');

给我的输入总是采用这种格式:06-25-2015 11:30:30 (月日年时分秒)

那是因为 strtotime 猜错了你的日期:

date('r', strtotime('08-05-2015 13:25:02')) -> Fri, 08 May 2015 13:25:02 -0500
date('r', strtotime('06-25-2015 11:30:30')) -> Wed, 31 Dec 1969 18:00:00 -0600

请注意,现在第一个值出现在 5 月 8 日:strtotime 正在考虑您的日期 dd-mm-yyyy,而您确实有 mm-dd-yyyy.

请注意第二个日期是 1969 年 12 月 - 这就是整数 0(又名布尔值 FALSE)作为我特定时区中的日期出现的方式。 FAILURE 为 FALSE,因为日历中没有月份 25

因为它猜错了,你将不得不做 date_create_from_format() 相反,告诉 php 你的日期是什么格式。