473,605 Members | 2,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 46092
"Kription" <kr******@cox.n et> wrote in message
news:mj_Pb.4702 $Ue.2767@lakere ad03...
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($pas tTimestamp)
{
$currentTimesta mp = time();
$timePassed = $currentTimesta mp - $pastTimestamp; //time passed in seconds
// Minute == 60 seconds
// Hour == 3600 seconds
// Day == 86400
// Week == 604800
$elapsedString = "";
if($timePassed > 604800)
{
$weeks = floor($timePass ed / 604800);
$timePassed -= $weeks * 604800;
$elapsedString = $weeks." weeks, ";
}
if($timePassed > 86400)
{
$days = floor($timePass ed / 86400);
$timePassed -= $days * 86400;
$elapsedString .= $days." days, ";
}
if($timePassed > 3600)
{
$hours = floor($timePass ed / 3600);
$timePassed -= $hours * 3600;
$elapsedString .= $hours." hours, ";
}
if($timePassed > 60)
{
$minutes = floor($timePass ed / 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 fefsensmrrjyahe eoceoq\! | 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 "CountScubu la" <me@scantek.hot mail.com> napisal w wiadomosci
news:Cv******** **********@news svr25.news.prod igy.com...
$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******** ************@co mcast.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 "CountScubu la" <me@scantek.hot mail.com> napisal w wiadomosci
news:Cv******** **********@news svr25.news.prod igy.com...
$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******** ************@co mcast.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
2742
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 I go and search the drive after the installation I don't see the 'sqlplus.hh'
6
1807
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 read one example. It has only one line in the main program
3
29027
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 h:minutes:seconds) as such: 0:15:34 (0 hours, 15 minutes, 34 seconds -> 934 seconds total) or as another example:
3
12800
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 for the irregular rotation of the earth, which is slowing down a little bit. So, a minute can contains 61 seconds ( range 0..60 ). Besides, the NTP protocol takes leap second into account, and UTC time also.
4
4047
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 advanced for compatibility with many browsers in present-day use; that Web authors should be aware of what JScript and ..NET may do, but cannot rely on it; and that MS documents describe the latest MS code as distinct from agreed standards.
5
4822
by: Totto | last post by:
Hi, Is it possible to convert date to dd mon yyyy hh:mi(24h) Thanks Totto
5
1576
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 collection performance issue except that there is no major memory to be garbage collected in this script. I'd be tempted to say it was a unix virtual memory issue except this is occuring at around 1/5th of my physical memory size. So something else...
2
4479
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 -I../include -g -02 -Wall -Wno-unused -pedantic -MT FileAppender.lo -MD -MP -MF .deps/FileAppender.Tpo -c FileAppender.cpp -fPIC -DPIC -o .libs/FileAppender.o ../include/log4cpp/Manipulator.hh:29: error: extra ';' make: *** Error 1
5
2688
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 I want to use 1 .hh file (define.hh) to store a bunch of variable information for about 6 or 7 other files. The problem that I am having is that I am getting multiple defines, how do I get around this problem? (the point of all of this is so that I...
37
4664
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 leap second? By "Unix time" I mean the integer returned by time() and similar functions. I'm concerned about the "down" case. Some of the software I've written
0
8004
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8425
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8418
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.