2

I want to display a time like this

80:00:00

Hours:Minutes:Seconds

When I use this

gmdate("H:i:s", $time)

It displays

08:00:00

gmdate() has hours display 0 once it reaches 24, start counting up to 24 again.

I have tried this

$minsec = gmdate("i:s", $time);
$hours = gmdate("d", $time)*24 + gmdate("H", $time);
echo $hours.':'.$minsec;

But this displays.

32:00:00

I understand from elsewhere on stackoverflow this might be because of daylight savings time. See here.

Convert days from gmdate() into hours?

I have not found any good solutions. What is a consistent, function solution to this problem.

Community
  • 1
  • 1
Goose
  • 4,764
  • 5
  • 45
  • 84

2 Answers2

1

Try this, works for me:

$minsec = gmdate("i:s", $time);    
$hours = (gmdate("d", $time)-1)*24 + gmdate("H", $time);    
echo $hours.':'.$minsec;

The -1 is important because the day is one when the $ time = 1 second. I do not know why, it must be because always have one day.

0

I think this is what you are trying to do, and this works for me:

<?php
$hour = gmdate("H", time());
if($hour < 10) {
echo gmdate("0H:i:s", time()); // you can just add a 0 in front of the hour if it is less than 10
}
else {
echo gmdate("H:i:s", time());
}
?>

hope this helps. if not comment and tell me if this isn't what you want

krummens
  • 837
  • 2
  • 17
  • 38
  • No, that's not my issue. If it was, a lowercase h could give me the 0 in front. I want to be able to display 25 hours instead of a day and 1 hour. – Goose Jan 09 '15 at 15:41
  • couldn't you just do what you shared in the link above? – krummens Jan 09 '15 at 15:55
  • It doesn't return the correct time because daylight savings time screws it up – Goose Jan 09 '15 at 16:03