1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to show real time depending on where the client is?

Discussion in 'C#' started by akinak, May 22, 2008.

  1. #1
    I am learning ASP. I know I can display current date and time using <%=now%>.
    But it shows static time, I want the time to be running. Also, how can I display it depending on the physical location of the person viewing the webpage.
    Please help.
     
    akinak, May 22, 2008 IP
  2. nubsii

    nubsii Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe such a thing would have to be implemented client-side if you wanted it to be ticking (while staying within reason). Someone will have to correct me if theres simply a simple asp.net way to do this. As far as I know you'll want javascript.. and it'll be something roughly like..
    
    var nowDate = new Date();
    
    document.someTextObject.value = "" + 
      nowDate.getHours() + ":" + 
      nowDate.getMinutes() + ":" + 
      nowDate.getSeconds();
    
    Code (markup):
    Then on the page you'll have a text input named "someTextObject" or something like that. This should get the time from where the client themselves is and display it in the text object, and then you'll need to run the clock every second to refresh it. I'm not exactly sure how to do that last part, but if you look up 'setTimeout Javascript' you'll find the details about that. I havent actually made one of these myself, but in theory it could recursively call itself.

    Here's the idea in pseudocode
    
    function RefreshClock()
      clear the timeout for the clock
      get the new time (this is the code sample above)
      run RefreshClock() in 1000 milliseconds  (this is accomplished via the setTimeout function)
    
    Code (markup):
    This way it sets itself to run in 1 second every time it finishes running. Sorry that I don't have a more developed answer, I've never actually needed something to tick before - but its definitely possible. Good luck!
     
    nubsii, May 23, 2008 IP
  3. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yeah..I guess thats the way to do it..but am still not able to.

    Still looking for some help..
     
    akinak, May 23, 2008 IP
  4. rkstech

    rkstech Active Member

    Messages:
    195
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Dear Akinak

    ASP works on the server and now() will always show the time on th server end

    To show the client End time you will need to use Javascript Time Functions
     
    rkstech, May 25, 2008 IP
  5. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yeah..but how to keep the time running..It only shows static time. Even if it has to be on the server side, how can I show running time?
     
    akinak, May 28, 2008 IP
  6. rkstech

    rkstech Active Member

    Messages:
    195
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
  7. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank You!! It worked :)
     
    akinak, May 29, 2008 IP