Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question JS Javascript Clock

    Hi! This is my first time here! I hope U can help me.

    I want to use a clock like this: http://joncom.be/code/css-clocks/
    But I want to show a local time from a specific city, like Bogotá.

    How can I achieve this?

    Thanks in advance!

    Bensita

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    in http://static.joncom.be/screen/script/css-clocks_1.js, change
    Code:
     dtDate:          new Date(),
    to a date adjusted for your city's offset.
    Bogotá is gmt -5, so we can set it like this

    Code:
     dtDate:          new Date(+new Date() + (new Date().getTimezoneOffset()* 1000 * 60) - (1000*60*60*   5  )) ,

    where the red number is the offset you want to adjust.

    what's going on here?
    we take the local time, adjust for the GMT offset to find zulu time, then adjust back the other way to the needed city's GMT offset.
    this gives us a date that is not actually current as it's run locally, but when visually displayed, it shows the correct time for the specified city.
    Last edited by rnd me; 09-18-2013 at 04:48 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    bensita (09-19-2013)

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Thanks!

    Hey thanks RND ME!

    I have changed that line and it seems to work fine!
    But I was playing with that numer (the 5) up and down, and it seems to change nothing!

    I if change it, the clock must show a different time right?

    Thanks in advance!

    Bensita

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You have to apply the same changes here:
    Code:
        fUpdate:        function() {
            // update time
            this.dtDate = new Date();
    All the code RndMe showed you does is change the *initial* time to a given time zone's time.

    But man, is that code poorly written! There are SO many ways it could be improved.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bensita (09-19-2013)

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,471
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Take a look at my clock script at http://www.felgall.com/jstip130.htm which as the timezone as one of the setup options.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    bensita (09-19-2013)

  • #6
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks to all of you!
    I finally get it.

    I appreciate felgall´s share, I think yours is really better!

    Thanks

    Bensita


  •  

    Tags for this Thread

    Posting Permissions

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