简体   繁体   English

在PHP中经过24小时的时间达到微秒

[英]Time to microseconds over 24hrs in php

I have to convert time in format of hh:mm:ss which is over 24hr, for instance 34:23:00. 我必须将hh:mm:ss格式的时间转换为24小时以上,例如34:23:00。 Is there any simple solution for this without using explode + strtotime functions? 有没有使用explode + strtotime函数的简单解决方案?

This should do the trick 这应该可以解决问题

<?php
$inputTime = "34:23:00";
$timeSplitted = explode(":", $inputTime);
$microSeconds = ($timeSplitted[0]*3600 + $timeSplitted[1]*60 + $timeSplitted[2]*1)*1000;
var_dump($microSeconds); // int(123780000)

This should give you what you're looking for (assuming 1 second = 1000000 microseconds). 这应该为您提供所需的内容(假设1秒= 1000000微秒)。

$time = '34:23:00';
$parts = explode(':', $time);   
$hours = !empty($parts[0]) ? $parts[0] : 0;
$minutes = !empty($parts[1]) ? $parts[1] : 0;
$seconds = !empty($parts[2]) ? $parts[2] : 0;

$microseconds = (($hours * 60 * 60) + ($minutes * 60) + ($seconds)) * 1000000;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM