PHP DOM元素字符串使用strotime()或preg_replace()中断

PHP DOM元素字符串使用strotime()或preg_replace()中断,php,dom,preg-replace,strtotime,Php,Dom,Preg Replace,Strtotime,我正在使用PHP从API获取XML(假设速度为3倍)。我正在从所有数据返回所有正确的字符串。当我尝试使用以下两种方法重新格式化时间字符串时,会出现问题: $dataset = $xmlDoc->getElementsByTagName( "Class" ); foreach( $dataset as $row ) { $xmlStartTimes = $row->getElementsByTagName( "StartTime" ); $xmlStartTime

我正在使用PHP从API获取XML(假设速度为3倍)。我正在从所有数据返回所有正确的字符串。当我尝试使用以下两种方法重新格式化时间字符串时,会出现问题:

$dataset = $xmlDoc->getElementsByTagName( "Class" );

foreach( $dataset as $row ) {

    $xmlStartTimes = $row->getElementsByTagName( "StartTime" );
    $xmlStartTime = $xmlStartTimes->item(0)->nodeValue;

    echo $xmlStartTime; // Gives eg. 12/30/1899 6:15:00 PM

    // Convert Time to 24H

    // Attempt 1:

    $cleanStartTime = preg_match('^12/30/1899 (0[1-9]|1[0-2]):(0[1-9]|[1-5][0-9]):([00]) (AM|PM|pm|am)$', $xmlStartTime, $matches);

    print_r($matches); // Gives empty array

    // Attempt 2:

    $cleanStartTime = date("H:i", strtotime("$xmlStartTime"));

    echo $cleanStartTime // Gives 1:00

}

感谢您查看。

这些时间超出了UNIX时间戳范围(32位)。改用DateTime扩展名:

<?php
$a = new DateTime("12/30/1899 6:15:00 PM");
echo $a->format("H:i");

这些时间超出了UNIX时间戳范围(32位)。改用DateTime扩展名:

<?php
$a = new DateTime("12/30/1899 6:15:00 PM");
echo $a->format("H:i");

var\u dump($xmlstatrttime)
,是字符串还是simplexmlement?
var\u dump($xmlstatrttime)
,是字符串还是simplexmlement?
打印日期(“H:i”,strottime('12/30/1899 6:15:00 PM')显示18:15,但仍然是很好的建议。太好了,我认为API给出的日期可能会产生奇怪的效果。@Mike B不在32位int的平台上。在windows上,您的行给了我
01:00
打印日期(“H:i”,标准时间('12/30/1899 6:15:00 PM')显示18:15,但仍然是很好的建议。太好了,我认为API给出的日期可能会产生奇怪的效果。@Mike B不在32位int的平台上。在windows上,您的线路给了我
01:00