Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2011, 11:25 AM   PM User | #1
Athro
New to the CF scene

 
Join Date: May 2011
Location: Belgium
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Athro is an unknown quantity at this point
JavaScript clock, adjustable depending on user input

Hello, everyone. I am currently on my way to create my own site, but I would like to create a ticking clock with javascript.
My only problem is this:
In the registration form for the users, I let them select in what timezone they are, so later on when they log in they would see a clock for that timezone.
How do I make this?
Help me please
Athro is offline   Reply With Quote
Old 05-03-2011, 11:39 AM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
One option is to use the javascript Date object to get the current hours, minutes and seconds from the users pc at 1 second intervals using setInterval() and display it.
bullant is offline   Reply With Quote
Old 05-03-2011, 11:42 AM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Do you already have a ticking clock
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 05-03-2011, 12:58 PM   PM User | #4
Athro
New to the CF scene

 
Join Date: May 2011
Location: Belgium
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Athro is an unknown quantity at this point
Thank you for the quick replies!

Yes, andrew, I do indeed have a script for a ticking clock (I'll show it in a second), but the fact is that I gave those <option><select></select></option> a few values that I inserted into MySQL database, and now I'd basically get those things out of my database (I know how to get them out), but also use those values (e.g. -6) to adapt my clock.

My ticking clock script:
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
Athro is offline   Reply With Quote
Old 05-03-2011, 10:00 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Something like this:
Code:
var today = new Date();
var adjDate = new Date(today.getTime());
adjDate.setHours(adjDate.getHours()+h);   // where h is -6, for example
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
Athro (05-04-2011)
Old 05-04-2011, 06:15 AM   PM User | #6
Athro
New to the CF scene

 
Join Date: May 2011
Location: Belgium
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Athro is an unknown quantity at this point
So I just replace that h by for example -6 or +6?
Ahh, thanks! This really helped me ^.^
Athro is offline   Reply With Quote
Old 05-06-2011, 10:59 PM   PM User | #7
Athro
New to the CF scene

 
Join Date: May 2011
Location: Belgium
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Athro is an unknown quantity at this point
Oh, one more thing, though, is there a special thing for summertime etc?
Athro is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:59 PM.


Advertisement
Log in to turn off these ads.