Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / December 2003

Tip: Looking for answers? Try searching our database.

JavaScript Clock Dilemma

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DeLpHi_gUy - 12 Dec 2003 12:26 GMT
I'm still quite new to JavaScript so excuse me if my question sounds stupid.
JavaScript is worlds apart from Object Pascal and I'm still finding my way
around.
I'm working on a JavaScript clock that will show the time for all major
Australian cities. I'm not sure how to approach the whole timezone offset
thing. I know there is a function getTimezoneOffset() but I'm not sure how
to implement it.

Here's a piece of code (implementing time for two cities only at this
stage). I would appreciate it someone could demonstrate how I can implement
an offset. Perth is 3 hours (or 180 minutes) behind Sydney, so how could I
implement the time difference?

function SydClock()
   {
   var SydTime=new Date();
   var SydHours=SydTime.getHours();
   var SydMins=SydTime.getMinutes();
   var SydSecs=SydTime.getSeconds();

    if (SydHours>=13)
      SydHours-=12;
    if (SydHours==0)
      SydHours=12;
    if (SydSecs<10)
      SydSecs="0"+ SydSecs;
    if (SydMins<10)
      SydMins="0"+ SydMins;
      {
    ClockFrm.SydDisplay.value=(SydHours + ":"
       + SydMins + ":" + SydSecs);
       setTimeout('SydClock()',1000);
       }
    }

 function PerthClock()
   {
   var PerthTime=new Date();
   var PerthHours=PerthTime.getHours();
   var PerthMins=PerthTime.getMinutes();
   var PerthSecs=PerthTime.getSeconds();

    if (PerthHours>=13)
      PerthHours-=12;
    if (PerthHours==0)
      PerthHours=12;
    if (PerthSecs<10)
      PerthSecs="0"+ PerthSecs;
    if (PerthMins<10)
      PerthMins="0"+ PerthMins;
      {
     ClockFrm.PerthDisplay.value=(PerthHours + ":"
       + PerthMins + ":" + PerthSecs);
       setTimeout('PerthClock()',1000);
     }
   }

Thanx in advance!

DeLpHi_gUy
DeLpHi_gUy - 13 Dec 2003 13:09 GMT
OK, I should also mention that some of the other cities are behind by one
and a half and hour hour. For example, Adelaide is 0.5 hours behind Sydney
while Darwin is 1.5 hours behind Sydney. Which means I have to offset the
hours and minutes.

Any tips will be appreciated.

Thx!

> I'm still quite new to JavaScript so excuse me if my question sounds stupid.
> JavaScript is worlds apart from Object Pascal and I'm still finding my way
[quoted text clipped - 56 lines]
>
> DeLpHi_gUy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.