SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation URGENTLY need Help

    The following outputs the time in London, followed by the time in Paris, which is one hour behind London. How do I extend the script in the <BODY> of the document to display the time in New York, which is 5 hours ahead of London. (without making any changes to the script in the <HEAD> of the document.)

    <HTML><HEAD><TITLE>City Times</TITLE>

    <SCRIPT LANGUAGE="JavaScript">
    function writeTime( city, time) {
    document.write( "It is " +
    time.getHours() + ":" +
    time.getMinutes() + " in " +
    city + "<P>");
    } <!-- End writeTime -->
    </SCRIPT>

    </HEAD><BODY><H1>

    <SCRIPT>
    var londonTime = new Date()
    var parisTime = null

    this.writeTime( "London", londonTime)

    parisTime = londonTime
    parisTime.setHours( parisTime.getHours() -1)
    this.writeTime( "Paris", parisTime)
    </SCRIPT>

    </H1></BODY></HTML>

    THANX 4 ANY1 THAT CAN HELP

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <SCRIPT>
    var londonTime = new Date()
    var parisTime = null
    var newYorkTime = null

    this.writeTime( "London", londonTime)

    parisTime = londonTime
    parisTime.setHours( parisTime.getHours() +1)
    this.writeTime( "Paris", parisTime)

    newYorkTime = londonTime
    newYorkTime.setHours( newYorkTime.getHours() -5)
    this.writeTime( "New York", newYorkTime)
    </SCRIPT>

    Note: Paris is ahead and New York is behind.

    Note2: I think that the date object handles rolover, i.e. when you subtract more hours than there are I think that it will adjust the month etc. Might be worth testing though.

    Of course this only works if the script is run in London since it is a browser script. If you run it anywhere else in the world it will give the local time.
    Last edited by dale_burrell; Dec 11, 2002 at 14:46.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  3. #3
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BIG THANX 4 YOUR HELP


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •