How to use gmdate() Function In PHP

The PHP gmdate() function is used to formatting the time. It can be employed to convert milliseconds to minutes and seconds.

PHP




<?php
  
$milliSeconds = 150000;
  
// Convert Milliseconds to minutes
// and seconds 
$format = 'i:s';
  
$time = gmdate($format, $milliSeconds / 1000);
  
echo "Time: " . $time;
  
?>


Output

Time: 02: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

...