将MySQL'TIME'字段拆分为单独的部分

时间:2015-02-13 07:08:13

标签: php mysql

我想将时间条目分成3个独立的变量,即:

07:15:20

$hour = 07
$minute = 15
$second = 20

我知道这对大多数人来说都是一个非常基本的问题,但我现在有点挣扎:)

2 个答案:

答案 0 :(得分:0)

我能想到的最简单方法

        <?php
        $time = "07:15:20";
        $time = explode(":",$time);
        $hour = $time[0];
        $minute = $time[1];
        $second = $time[2];
        ?>

答案 1 :(得分:0)

<?php
$time = "07:15:20";
list($hour,$minute,$second) = explode(":", $time);
print $hour . " - " . $minute . " - " . $second; 
?>

演示:http://3v4l.org/NWa8L