473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

seconds converted to HH-MM-SS

Hello,

I am having a nightmare of a time getting seconds converted to
hour-minute-seconds

I have a third party application that outputs only in seconds since

so if someone has been logged in for 1 minute, the time value would be 60,
if they were on for 5 minutes and 3 seconds the value would be 303

what I need is a way to take the 303 seconds and convert it to a human
readable:
0 hours 5 minutes and 3 seconds

and if possible; if hours = 0 then it wouldn't display - the same for
minutes.

Thank you in advance !!

-L"k"
*noob*
Jul 17 '05 #1
6 46048
"Kription" <kr******@cox.net> wrote in message
news:mj_Pb.4702$Ue.2767@lakeread03...
Hello,

I am having a nightmare of a time getting seconds converted to
hour-minute-seconds

I have a third party application that outputs only in seconds since

so if someone has been logged in for 1 minute, the time value would be 60,
if they were on for 5 minutes and 3 seconds the value would be 303

what I need is a way to take the 303 seconds and convert it to a human
readable:
0 hours 5 minutes and 3 seconds

and if possible; if hours = 0 then it wouldn't display - the same for
minutes.

Thank you in advance !!

-L"k"
*noob*


try this:

$t = (5 * 60) + 3; // 5 minutes and 3 seconds
print date("H:i:s",-57600 + $t);

will print "00:05:03"

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2
Kription wrote:
I am having a nightmare of a time getting seconds converted to
hour-minute-seconds (snip) what I need is a way to take the 303 seconds and convert it to a human
readable:
0 hours 5 minutes and 3 seconds

and if possible; if hours = 0 then it wouldn't display - the same for
minutes.


#v+
<?php
function secs2hms($secs) {
if ($secs<0) return false;
$m = (int)($secs / 60); $s = $secs % 60;
$h = (int)($m / 60); $m = $m % 60;
return array($h, $m, $s);
}

for ($i=0; $i<16; ++$i) {
echo implode(', ', secs2hms($i*817)), "\n";
}
?>
#v-

What this script doesn't do, I'll leave up to you :)

Happy Coding :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
Kription wrote:

what I need is a way to take the 303 seconds and convert it to a human
readable:
0 hours 5 minutes and 3 seconds


Well, I wrote this yesterday. Does the job, but I'd be very interested
to hear what people think about efficiency and processor cost. Is a
funciton like this wildly unreasonable?

// timePassed is a function to turn a time into a more human-friendly format
// Provide it with the number of seconds that have passed, and it will
return a more suitable
// description of how much time has passed.

function timePassed($pastTimestamp)
{
$currentTimestamp = time();
$timePassed = $currentTimestamp - $pastTimestamp; //time passed in seconds
// Minute == 60 seconds
// Hour == 3600 seconds
// Day == 86400
// Week == 604800
$elapsedString = "";
if($timePassed > 604800)
{
$weeks = floor($timePassed / 604800);
$timePassed -= $weeks * 604800;
$elapsedString = $weeks." weeks, ";
}
if($timePassed > 86400)
{
$days = floor($timePassed / 86400);
$timePassed -= $days * 86400;
$elapsedString .= $days." days, ";
}
if($timePassed > 3600)
{
$hours = floor($timePassed / 3600);
$timePassed -= $hours * 3600;
$elapsedString .= $hours." hours, ";
}
if($timePassed > 60)
{
$minutes = floor($timePassed / 60);
$timePassed -= $minutes * 60;
$elapsedString .= $minutes." minutes, ";
}
$elapsedString .= $timePassed." seconds";

return $elapsedString;
}

If you think it's what you're looking for, feel free to use it.
--
Bob
London, UK
echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"
Jul 17 '05 #4
Use gmdate() instead. The extra hours that you're getting comes from the
time zone difference between your and Greenwich, and would change depending
on where you are (I got error from your code, for instance, because the
timestamp was negative).

gmdate("H:i:s", $t) will yield exactly what's needed.

Uzytkownik "CountScubula" <me@scantek.hotmail.com> napisal w wiadomosci
news:Cv******************@newssvr25.news.prodigy.c om...
$t = (5 * 60) + 3; // 5 minutes and 3 seconds
print date("H:i:s",-57600 + $t);

will print "00:05:03"

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #5
Thank you..

Doh.. Guess who feels dumb now ! - it was so simple, I should have known
better.

-L"k"

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:6J********************@comcast.com...
Use gmdate() instead. The extra hours that you're getting comes from the
time zone difference between your and Greenwich, and would change
depending
on where you are (I got error from your code, for instance, because the
timestamp was negative).

gmdate("H:i:s", $t) will yield exactly what's needed.

Uzytkownik "CountScubula" <me@scantek.hotmail.com> napisal w wiadomosci
news:Cv******************@newssvr25.news.prodigy.c om...
$t = (5 * 60) + 3; // 5 minutes and 3 seconds
print date("H:i:s",-57600 + $t);

will print "00:05:03"

--
Mike Bradley
http://www.gzentools.com -- free online php tools


Jul 17 '05 #6
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:6J********************@comcast.com...
Use gmdate() instead. The extra hours that you're getting comes from the
time zone difference between your and Greenwich, and would change depending on where you are (I got error from your code, for instance, because the
timestamp was negative).

gmdate("H:i:s", $t) will yield exactly what's needed.


dont you just hate it when it right under your knose?

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter Moscatt | last post by:
I have just installed MySQL++ 1.7.9 using the RPMs from Rpmfind.com. It installed all Ok. The reason why I installed the RPM over the source was that I can't get the source to compile. When...
6
by: poison.summer | last post by:
Hi I am trying to use zthread.hh but I have many questions. I can't understand it. For example if my thread is waiting one message and try to excute some commands according to the message. I...
3
by: fred14214 | last post by:
I need to be able to enter an elapsed time into a text field. This time then needs to be converted into seconds and stored in a field in some table. The user will enter a time (format is...
3
by: nriesch | last post by:
In the documentation, the "Second" property of class DateTime is a value between 0 and 59. In UTC time, approximately every year of so, a leap second is added at 00:00:00 UTC, so as to account...
4
by: Dr John Stockton | last post by:
I'm starting a new thread, for clarity. I'm assuming that it's ECMA-262 3rd Edn (1999) that we should be using for Web pages; that 4th Edn (what's its present status? is it available?) is too...
5
by: Totto | last post by:
Hi, Is it possible to convert date to dd mon yyyy hh:mi(24h) Thanks Totto
5
by: charlie strauss | last post by:
Below is a simple program that will cause python to intermittently stop executing for a few seconds. it's 100% reproducible on my machine. I'd be tempted to say this is a nasty garbage...
2
Colloid Snake
by: Colloid Snake | last post by:
Hello, I was attempting to configure log4cpp to monitor some logs on my *nix box, and when I run 'make' I get this error message: # make g++ -DHAVE_CONFIG_H -I. -I. -I../include...
5
by: UofCRussell | last post by:
I will give the general idea here, I am taking a Software development class (im a computer engineering student) and I have run into a road block (could be the coffee and the fact that I am sick) but...
37
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.