hh:mm: SS 到毫秒

Hh: mm: SS to milliseconds

我想将时间 (hh:mm:ss) 转换为毫秒。那我该怎么做呢?

例如: 时间是:00:00:11

注意:我需要 PHP 中的代码。

$time = '11:22:33';    
$seconds = strtotime("1970-01-01 $time UTC");
$miliseconds = $seconds * 1000;

echo $seconds ."\n" . $miliseconds;

输出: 40953 40953000

$string = "00:00:11";
$time   = explode(":", $string);

$hour   = $time[0] * 60 * 60 * 1000;
$minute = $time[1] * 60 * 1000;
$sec    = $time[2] * 1000;

$result = $hour + $minute + $sec;

echo $result;

日期到时间的转换如下


    $Given_date   = date('H:i:s');

    $hour         = date('H',strtotime($Given_date));
    $minute       = date('i',strtotime($Given_date));
    $seconds      = date('s',strtotime($Given_date));

    $sec_to_milli = $seconds * 1000;            //seconds to milliseconds
    $min_to_milli = $minute * 60 * 1000;        //minutes to milliseconds
    $hrs_to_milli = $hour * 60 * 60 * 1000;     //hours to milliseconds

    $milliseconds = $hrs_to_milli + $min_to_milli + $sec_to_milli;

    echo $milliseconds;