strtotime 不适用于微秒

strtotime doesnt work with microseconds

尝试将包含微秒的字符串转换为 unix 时间戳时,strtotime 函数似乎不起作用。我不关心将微秒保留在 unix 时间戳中。

示例:

$date = '2017-03-21-10:58:01.7888';
echo strtotime($date); // always outputs 0

PHP不支持带微秒的格式,请参阅list of compound formats(日期和时间)。您必须将其转换为受支持的格式。如果时间戳保证使用这种格式,可以在点处拆分,然后使用第一部分获取不带微秒的时间戳:

echo strtotime(split(".", $data)[0]);

根据these tests and the PHP Manual,问题是日期和时间之间的破折号:

5.0.0 Microseconds began to be allowed, but they are ignored.