Convert Seconds To HH:MM:SS
Oct 31, 2004
Could reorganize to make it a bit shorter, but. . .
//*******************************************************
//Convert seconds to HH:MM:SS
//*******************************************************
function convertHMS(sec)
{
//From JS FAQ by Liorean
Number.prototype.toDecimals=function(n){
n=(isNaN(n))?
2:
n;
var
nT=Math.pow(10,n);
function pad(s){
s=s||'.'
return (s.length>n)?
s:
pad(s+Ɔ');
}
return (isNaN(this))?
this:
(new String(
Math.round(this*nT)/nT
)).replace(/(.d*)?$/,pad);
}
if(sec>59)
{
var hrs=sec/3600;
if(hrs<0)
{
hrs="00";
var min=hrs*60;
min=min.toDecimals(8);
var snd=min.substring(min.indexOf('.'),min.length);
min=min.substring(Ɔ',min.indexOf('.'));
if(min<10)
{
min=Ɔ'+min
}
snd=Math.round(snd*60);
if(snd<10)
{
snd=Ɔ'+snd;
}
var tm=hrs+':'+min+':'+snd;
}
else
{
hrs=hrs.toDecimals(8);
var min=hrs.substring(hrs.indexOf('.'),hrs.length)
hrs=hrs.substring(Ɔ',hrs.indexOf('.'));
if(hrs<10)
{
hrs=Ɔ'+hrs;
}
min=min*60
min=min.toDecimals(8);
var snd=min.substring(min.indexOf('.'),min.length);
min=min.substring(Ɔ',min.indexOf('.'));
if(min<10)
{
min=Ɔ'+min
}
snd=Math.round(snd*60);
if(snd<10)
{
snd=Ɔ'+snd;
}
var tm=hrs+':'+min+':'+snd;
}
}
else
{
if(sec<10)
{
sec="0"+sec;
}
var tm="00:00:"+sec
}
return tm;
}
View 7 Replies
ADVERTISEMENT
May 18, 2011
I am creating a JS function that takes a time input in minutes only and divides that number by an inputted digit. I would like to know how we use Javascript to convert that result into minutes and seconds.For instance, 30 (1800 seconds) divided by 4 = 450 seconds. How do I show that as 7:30? I can divide by 60 to get 7.5, but I don't know how to go from there. I got as far as the following, then got stuck.
PHP Code:
<form id="form2"><table>
<tr>
<td class="alignright">
[code].....
View 24 Replies
View Related
Apr 12, 2011
i found a script that starts counting seconds from 0 till x. i wanted it to display the seconds in mm:ss (minutes : seconds) .. now i only get "NaN:0" (NaN for minutes and 0 for seconds). this is how i ended up : [URL]
View 1 Replies
View Related
Aug 2, 2010
I would like to create a program which converts some letters into different ones.
1) I want 2 text areas (input and output) + "convert" button
2) if I type in the input area the letters "ea" I would like it to be converted into "a", so that If I type "cambrea" and press "submit" the output text will have "cambra".
3) if I type "e " which is (e+space) I want it to be converted into " " which is "space" example: if I type the word "spine " it should be converted into "spin , note that there is a space after "spin ".
4) If I type any vowel before "o" it should render "o", example: gambuo becomes gambo.
would this be possible? I'm not very familiar with Javascript even though I can modify it.
View 1 Replies
View Related
Sep 11, 2010
I need to develop this feature for a charity site displays a number that counts up 1 every 15 seconds. This is to show how many times a kid is abused in this country.
I figured this piece of code was a good start:
function doSomething() {
setTimeout('doSomething()',15000);
}
View 2 Replies
View Related
Jan 19, 2007
I'm trying to write a script that will run a function every x many seconds. I'd have thought that there would be a function for this already, but I didnt find anything. So I wrote the following..
do{
now = new Date
seconds = now.getSeconds()
if(seconds+"2" == now.getSeconds()){
function();
}}
while(1)
Which didn't work.. just hung the browser. BTW 2 is the interval in seconds.
View 7 Replies
View Related
Sep 16, 2009
i have a form.. i validated it..if the form has an empty field, instead of popping up an alert box, i need to display a message that goes off say after 5 seconds..
View 1 Replies
View Related
May 31, 2010
I have some ad code in a smarty .tpl file that I want to refresh every 10 seconds so it will load a new ad. My ads are getting plenty of views but I want people to multilple ads in one page view instead of when the whole page is refreshed.
<div id="ads_refresh">
{if $ads->ad_top != ""}
</div>
All the code I have browsed on the web want to load an external file into a div instead of just refreshing the div with the content already in it.
View 3 Replies
View Related
Jun 11, 2009
I'm writing a script for a chatbox and I want to run the function to retrieve the messages from the .xml file every five seconds or so. How would I do that?
View 3 Replies
View Related
Feb 16, 2010
I want to be able to hide a div ten seconds after clicking on a link.
View 24 Replies
View Related
Oct 25, 2009
i implement jquery tab in my new website but i have problem while page loading, when i first time open page it display random data without css for 2-3 second and then everything is ok, if anyone know the problem let me know[URL]...
View 1 Replies
View Related
Feb 19, 2009
Am having 5 images,
image1,image2 upto image5,
when the page is loaded initially i want to display image1 for 8second, then next 5second image2, next 5 seconds image3,next5 secondimage4,next5second image5,
then again i want to display imag1 for 8 second ...continue this loop,
Using java script i want to do this , any good suggestion for this,,
i have tried like set interval function. how to disable other image and how to call the images for 5sec,
View 2 Replies
View Related
Apr 24, 2011
We have a problem in our currently built website, in chrome+firefox the website works great but in IE 7+8+9 the javascript stops working after few seconds or after several commands a user do in the website.
The url is : [url]
View 1 Replies
View Related
Jun 28, 2009
How do i change an image every 3 seconds between 3 images and on a loop? What is the simplest way to do it?
View 3 Replies
View Related
Sep 2, 2009
I have a welcome message on my site and would like to automatically hide it after several seconds. I can't find anything usable after searching over the internet
View 2 Replies
View Related
Jul 8, 2010
This is the script to hide the div (adsdiv)Its working on all browser except IE
<script type="text/javascript">
function closeMyAd() {
document.getElementById("adsdiv").style.display = "none" ;
[code]....
View 6 Replies
View Related
Sep 19, 2010
I found this code, written by Philip M on another thread [URL] of this forum:
<div id = "adsdiv">This ad will close in
<span id = "closingtimer">31</span>
seconds
</div>
<script type="text/javascript">
[Code].....
I need to reverse the script to show a div after 30 seconds, not to hide it.
View 2 Replies
View Related
Dec 5, 2010
I want a code that changes text (of maybe a div) after 10 seconds.
So like i could have some text and a link on my page then after 10 seconds it will change to something else and i can make it change to as many things as i want. Then when it goes threw them all it starts over.
View 7 Replies
View Related
Nov 9, 2011
topic has been answered
View 1 Replies
View Related
Nov 11, 2011
I am building a website, where I need a page to after a delay of five seconds upon load, automatically load a random url, from an array of a couple of different urls. Any idea how to do this ? I found something that does this, but without the 5 second delay..
<script type="text/javascript">
var urls = new Array();
urls[0] = "http://www.AAA.com";
urls[1] = "http://www.BBB.com";
urls[2] = "http://www.CCC.com";
[Code]...
View 10 Replies
View Related
Feb 24, 2007
I'm using dreamweaver and I'm looking for a script code for after sending a form (after submitting it), after 10 seconds the page jumps to an new URL.
View 2 Replies
View Related
Feb 2, 2006
I have a little DIV pop-up window that I want to automatically go away after X seconds.
Basically, it should go away after 3 seconds, but the 3 seconds should be refreshed back to Ɖ' when the mouse goes over the popup window. Make sense?
View 5 Replies
View Related
Jun 25, 2006
I have built an admin area for employees of a business. Once logged-in, if they sit idle for 5 minutes their session will be killed ( the time may vary depending on the employee ). I do all this with php but don't really know much about javascript.
What I would like to do is start playing a small sound repeatedly when the employees session is about 30 seconds from expiring. ( this will give the employee time to click on a link to keep their session alive )
So when the page loads, I would like to pass a length of time in seconds to a javascript. So if the employee can sit idle for 5 minutes, that would be 300 seconds. Minus the 30 seconds that I would like the alarm to be playing for which gives us 270 seconds. ( I'll pass this number to the script with PHP, the script does not have to figure this out... just to be clear. )
So I'm looking for something like this:
- On page load, tell javascript to count down a specific number of seconds ( 270 )
- When the countdown reaches 0, start playing sound file repeatedly.
Sounds easy enough but I haven't been able to find anything like this yet. The only ones I've seen actually display the countdown which I don't want. I want this to count down invisibly. Oh and it should hopefully work in both IE and Firefox.
View 1 Replies
View Related
Jun 10, 2009
I have few backgrounds for my website, which want to change background image after few seconds with some fading effects.
I am using <body><div id="bg">Contetns</div></body>
View 1 Replies
View Related
Feb 13, 2011
I need to redirect the user to another url in 5 seconds without the "click" sound.
you'll notice that this:
Code JavaScript:
setTimeout("location.href='http://myurl';",5000);
produces a "click" sound (maybe only in IE). I want to avoid this sound in my code (I know this can be changed in windows in the user's computer).
View 5 Replies
View Related
Apr 11, 2007
I have this below which causes an alert after 10 seconds. How would I keep the alert going every 10 seconds after?
<script type="text/javascript">
//If the time is less than 10,
//you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
var d = new Date();
var time = d.getSeconds();
if (time > 10)
{
alert("Hello day!")
}
</script>
</body>
</html>
View 7 Replies
View Related