General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 16th, 2002, 10:22 AM
nousey nousey is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 9 nousey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
time conversion

Hi people

If somebody gives you a total number of seconds, for example 1890 seconds, what is the best way to convert this into total number of hours, minutes and seconds?

Thanks!

Reply With Quote
  #2  
Old November 17th, 2002, 07:43 PM
Chrisw84 Chrisw84 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 2 Chrisw84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Chrisw84 Send a message via AIM to Chrisw84
ill just throw up some psuedocode of what i think would be the best way todo this


first off have a form unless its a set time you are converting but in that case why convert it just write the answers, i dont know what you are doing so here lol

on the form have a text field called "secinput" or whatever you want

then
PHP Code:
 $seconds "$secinput";
echo(
$seconds);

$minutes "$secinput / 60";
echo(
$minutes);

$hours "$secinput / 60 / 60";
echo(
$hours);

$days "$secinput / 60 / 60 / 24";
echo(
$days); 


like i said its just some pseudocode ideas, i dont even know if thats how you do calculations in php im just a noob and i dont know what exactly you want todo but since no one else responded i thought i would. also you will get decimal answers with the method i showed.

good luck

Last edited by Chrisw84 : November 17th, 2002 at 07:47 PM.

Reply With Quote
  #3  
Old November 23rd, 2002, 03:28 AM
serg4444 serg4444 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 16 serg4444 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just make it separate:


$days = floor($secinput / 60 / 60 / 24);
$hours = floor(($secinput -$days*60*60*24)/ 60 / 60);
...etc..

echo"$days-$hours-$minutes-$seconds";


Sincerely,
Sergey Booyny
AlarIT programmer
http://www.AlarIT.com

Reply With Quote
  #4  
Old July 7th, 2003, 10:00 AM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
this worked quite well for me, although the way that serg4444 suggests looks better:

PHP Code:
if($seconds 86400

   
$day 0
}else{ 
   
$day floor($seconds 86400); 
   
$seconds -= 86400*$day


if(
$seconds 3600

   
$hours 0
}else{ 
   
$hours floor($seconds 3600); 
   
$seconds -= 3600*$hours


if(
$seconds 60

   
$minutes 0
}else{ 
   
$minutes floor($seconds 60); 
   
$seconds -= 60*$minutes


$uptime "$day days $hours hours $minute minutes $seconds seconds"

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > time conversion


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT