Convert a time in the format H:i:s (hours:minutes:seconds) to milliseconds in PHP. In this code, we first split the time string into hours, minutes, and seconds using the explode function. Then, we calculate the total time in seconds by converting hours and minutes to seconds and adding the seconds. Finally, we multiply the total seconds by 1000 to get the time in milliseconds. Since we don't have any milliseconds in the first place, they will always be zeros.
Source code viewer
- $time = '13:37:00';
- $milliseconds = (($hours * 3600) + ($minutes * 60) + $seconds) * 1000;
- echo $milliseconds;
- // Output: 49020000Programming Language: PHP