2011-03-17 75 views

回答

8

不需要做字符串轉換或數組操作:

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

+1,因爲我沒有想到'sscanf()':) – alex 2011-03-17 02:16:06

+1

+1 for'sscanf()' – timdream 2011-03-17 02:23:17

+0

的確很好:)。 – 2011-03-17 06:19:40

3

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

+0

感謝您r幫助:) – 2011-03-17 02:14:52

+0

這確實節省了代碼和時間。 – 2011-03-17 02:19:40

+0

@Aung:Cooper的回答更好,因爲它不取決於數字的位數。 – timdream 2011-03-17 02:24:35

1
$value = "10:10"; 

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

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

var_dump($milliseconds); // 610000 
+0

感謝您的幫助 – 2011-03-17 02:15:14

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

愛數組:) – 2011-03-17 02:20:20

相關問題