Friday, 15 August 2014

date - How do I format an amount of milliseconds into minutes:seconds:milliseconds in PHP? -


itemprop = "text">

I have a total of milliseconds (i.e. 70370) and I want to display it in minutes: seconds: millisecond i.e. 00 : 00: 0000.

How can I do PHP?

don 'fall into the trap of using date tasks for this! You have a time interval here, not the date.

  Date ("h: i: su", $ mytime / 1000)  

but for the dates of the use of the date function (gasp!) It does not operate in the way you want it in this situation - it takes timezone and daylight savings while formatting date / time.

Instead, you probably want to make a few simple maths:

  $ input = 70135; $ USec = $ input% 1000; $ Input = floor ($ input / 1000); $ Sec = $ input% 60; $ Input = floor ($ input / 60); $ Min = $ input% 60; $ Input = floor ($ input / 60); // and so on, as long as you need  

No comments:

Post a Comment