Hh:mm:SS到毫秒

时间:2017-03-01 06:21:03

标签: php datetime milliseconds

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

例: 时间是:00:00:11

注意:我需要PHP代码。

3 个答案:

答案 0 :(得分:2)

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

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

输出: 40953 40953000

答案 1 :(得分:2)

ndb

答案 2 :(得分:0)

日期到时间的转换将如下所示


    $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;