PDA

View Full Version : Date and Time code question



eternity01
12-17-2004, 03:11 PM
I am wanting to have a script that gives the current date and time in Central US time. How do I get that? Here is the script I would like to use:
Date And Time Script (http://www.dynamicdrive.com/dynamicindex6/clock3.htm)
Thanks,
Eternity

simonf
12-17-2004, 03:37 PM
Hi

Try the link http://www.dynamicdrive.com/dynamicindex6/index.html lots of clocks and code etc to play with. rgds,Simonf ;)

eternity01
12-17-2004, 03:40 PM
Thanks, but that's where I got the clock in my question. I was wanting it to give Central US time.

Robin

simonf
12-17-2004, 03:49 PM
Hi

Why..... if I signon to the site and I live in South Africa, do I care what the time is in central USA... get my drift..... the time that relative to the user is their time not necessarily yours... unless your aiming at doing world clocks etc....rgds,Simon ;)

eternity01
12-17-2004, 03:51 PM
Because I want to use it on a website competition vote page and they use US Central time.

cr3ative
12-17-2004, 04:16 PM
Uhm. This is a hard one to deal with, as the clocks get the users local system time.

cr3ative

simonf
12-17-2004, 04:34 PM
Hi

I've seen this somewhere.. please give us time to find and you will get your answer. rgds,Simon ;) now where the hell was that thing......?????

eternity01
12-17-2004, 05:06 PM
Thanks. I appreciate it very much :)
Robin

simonf
12-18-2004, 04:17 PM
Hi

Why not try an in-line frame and use the source from say a worldclock viewing say Chicago try http://www.timeanddate.com/worldclock/city.html?n=64

Q: Cr3ative how would you position this frame to read only the data/time area for this.

rgds,Simonf :eek:

cr3ative
12-18-2004, 06:52 PM
*jaw drops*

Errr... I don't think we can.
We need to find a time server that streams to a javascript variable - that'd be nice...

cr3ative

eternity01
12-19-2004, 02:05 AM
Ok well thanks everyone for trying. I really appreciate the help.

Have a Merry Christmas!!
Hugs,
Robin

simonf
12-21-2004, 10:30 AM
Hi

OK.. almost got it to work. Has a small problem with time and date around the date change. Cr3ative, please take a look and see what I missed, my eyes are old and just do not seem to pick up the fault.

The code that works most of the time (i think :eek: ) is:

<BODY><TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD width=150>
<FORM name=Central>
<P><INPUT size=64 name=Clock></P></FORM>
<P>
<SCRIPT language=javascript>
<!--Designed by simon.fish@cherrycreektrading.co.za

function show()
{
var Cdate=new Date()
var day=Cdate.getDate()
var month=Cdate.getMonth()+1
var year=Cdate.getFullYear()
var zone=Cdate.getTimezoneOffset()
var central=360
var hours=Cdate.getHours()+((zone-central)/60)
var minutes=Cdate.getMinutes()
var seconds=Cdate.getSeconds()
if (hours<=9)
hours="0"+hours
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
document.Central.Clock.value="U.S Central Time is now: "+hours+":"+minutes+":"+seconds+" and the current date is "+month+"/"+day+"/"+year

setTimeout("show()",1000)
}
show()
//-->
</SCRIPT></BODY>

rgds,Simonf :cool:

cr3ative
12-21-2004, 10:56 AM
Ah, very good code. I didn't know about getTimezoneOffset().. you learn something new every day.

(the fault doesn't seem to show up when I test it... odd)

Merry Christmas
cr3ative

eternity01
12-21-2004, 11:19 AM
Thank you both very much!! Im off to put it on my site.
Hugs,
Robin

simonf
12-21-2004, 02:02 PM
HI Cr3ative, if you change your time a few minutes to midnight on the date timeline it seems to happen then, Only for an hour and all is then fine!! rgds,Simon:cool:

simonf
12-23-2004, 07:46 PM
Hi

I think I was being really dumb, as I now seem to have fixed it 100%. Cr2ative, see you on-line please can you test for me. Code is:

<FORM name=WSTC><INPUT size=63 name=WSClock></P></FORM>
<SCRIPT language=javascript>
// Web Server Time Script (Designed by simon.fish@cherrycreektrading.co.za)
// Last updated: 12/23/2004
// Designed to show your users the time and date on your server
// this example is set to US central time, to modify change the getUTCHours()-6 parameter to reflect your timezome from GMT (i.e 0=GMT)
// Permission granted and modified by Dynamicdrive.com to include script in archive
function show()
{
var Cdate=new Date()
var day=Cdate.getUTCDate()
var month=Cdate.getUTCMonth()+1
var year=Cdate.getUTCFullYear()
var hours=Cdate.getUTCHours()-6
var minutes=Cdate.getUTCMinutes()
var seconds=Cdate.getUTCSeconds()
if (hours<=9)
hours="0"+hours
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
document.WSTC.WSClock.value="U.S Central Time is now: "+hours+":"+minutes+":"+seconds+" and the current date is "+month+"/"+day+"/"+year

setTimeout("show()",1000)
}
show()
//-->
</SCRIPT>

rgds,Simonf :cool:

cr3ative
12-24-2004, 07:51 AM
The metaphorical thumb is up.

Thanks for spending the time to do that, Simon.