在PHP中将mm:ss转换为毫秒

时间:2011-03-17 02:10:07

标签: php time

请告诉我如何在PHP中将mm:ss转换为毫秒。

$value = "10:10"

$ms = ...

4 个答案:

答案 0 :(得分:10)

无需进行字符串转换或数组操作:

sscanf($value, "%d:%d", $minutes, $seconds);
$ms = $seconds * 1000 + $minutes * 60 * 1000;

答案 1 :(得分:3)

$ms = intval(substr($value, 0, 2))*60*1000 + intval(substr($value, 2, 2))*1000;

答案 2 :(得分:3)

$value = "10:10";
$time = explode(':',$value);
$ms = $time[0]*60000 + $time[1]*1000;

答案 3 :(得分:1)

$value = "10:10";

list($minutes, $seconds) = explode(':', $value);

$milliseconds = $seconds * 1000 + $minutes * 60000;

var_dump($milliseconds); // 610000