Splite STring得到错误Offcet

时间:2017-04-04 10:30:38

标签: php string

我正在尝试拆分包含时间的字符串,如“23:25:00”

我希望得到几小时和几分钟,但它会产生错误,如偏移......

我试过了:

$time= "12:12:50";
$time = explode(":", $time);
echo $time[0]; // Hours
echo $time[1]; // minutes

1 个答案:

答案 0 :(得分:1)

$time = '12:23:59';
$timeParts = explode(':', $time);

echo $timeParts[0] . ': hours';
echo $timeParts[1] . ': minutes';
echo $timeParts[2] . ': seconds';