How to use Division and Modulus In PHP

The basic method to convert milliseconds to minutes and seconds is by using basic arithmetic operations.

PHP




<?php
  
$milliSeconds = 150000;
  
// Convert Milli Seconds to minutes and seconds
$minutes = floor($milliSeconds / (60 * 1000));
$seconds = floor(($milliSeconds % (60 * 1000)) / 1000);
  
echo "Minutes: " . $minutes . "\n";
echo "Seconds: " . $seconds . "\n";
  
?>


Output

Minutes: 2
Seconds: 30

PHP Program to Convert Milliseconds to Minutes and Seconds

This article will show how to convert Milliseconds to Minutes and Seconds in PHP. When working with time-related calculations, it’s common to encounter durations in milliseconds. Converting milliseconds to minutes and seconds is a useful task in various applications.

Table of Content

  • Using Division and Modulus
  • Using gmdate() Function

Similar Reads

Using Division and Modulus

The basic method to convert milliseconds to minutes and seconds is by using basic arithmetic operations....

Using gmdate() Function

...

Contact Us