Number of seconds to minutes and seconds

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Number of seconds to minutes and seconds

Post by ianripping »

Hi,

I have a script that is returning a time in a number of seconds eg 218 seconds.
Is there a function in PHP,(im sure there will be) that will change say 69 seconds, to 01:09?

Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Does

Code: Select all

<?php echo date('H:i:s', 218); ?>
suffice?
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post by ianripping »

volka wrote:Does

Code: Select all

<?php echo date('H:i:s', 218); ?>
suffice?
This print 01:03:38 - why is the hour 01? it should be 00
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

oh sorry, date() takes the server's timezone into account.
00:00:00 1970 GMT was 01:00:00 1970 in your timezone.

Code: Select all

<?php echo gmdate('H:i:s', 218); ?>
prints 00:03:38
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Alternately, you could use printf's (that's the username, not the function) snippet found in Code Snippets.
ianripping
Forum Newbie
Posts: 17
Joined: Thu Feb 05, 2004 3:20 am
Location: Leeds, UK

Post by ianripping »

volka wrote:oh sorry, date() takes the server's timezone into account.
00:00:00 1970 GMT was 01:00:00 1970 in your timezone.

Code: Select all

<?php echo gmdate('H:i:s', 218); ?>
prints 00:03:38
Thanks, works great
Post Reply