Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tomasosho's avatar

How to display 100secs as 1m40s

how can i display 100seconds as 1m40s I wanted to convert the 100s to minutes, that is 100/60. But i'm not sure what to do from there.

0 likes
8 replies
tykus's avatar
tykus
Best Answer
Level 104
$time = 100;
intdiv($time, 60) . 'm'.$time % 60 . 's';

You could make a helper method which takes a number of seconds if needed.

1 like
kokoshneta's avatar

@tomasosho It’s very easy to make it, though – just change the H:i:s format to i\ms\s and it will show 1m40s instead of 00:01:40.

Sinnbeck's avatar

@kokoshneta that's what I was hinting at :) part of being a programmer is to Google, read the code and understand it. Then tweak it to do what you want it to do. I just assumed that this was a still people would learn over time

Please or to participate in this conversation.