Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Display the server time and refresh every 1 sec using Javascript in asp.net

Display the server time and refresh every 1 sec using Javascript in asp.net

Scheduled Pinned Locked Moved JavaScript
helpcsharpjavascriptasp-netsysadmin
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G Mariappan a Murugan
    wrote on last edited by
    #1

    Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan

    L J 2 Replies Last reply
    0
    • G G Mariappan a Murugan

      Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Javascript runs in the client browser, so will reflect the client's timezone. You need to use a mechanism (code behind, AJAX?) to get the data from the server.

      Veni, vidi, abiit domum

      G 1 Reply Last reply
      0
      • L Lost User

        Javascript runs in the client browser, so will reflect the client's timezone. You need to use a mechanism (code behind, AJAX?) to get the data from the server.

        Veni, vidi, abiit domum

        G Offline
        G Offline
        G Mariappan a Murugan
        wrote on last edited by
        #3

        Hi Richard, Thanks for your reply i used javascript to get the server time please see the below code its works for me //Users time var timeLocal = new Date(); var timeServer = new Date('<%= DateTime.Now.ToString()%>'); //Calculate the difference (returns milliseconds) millDiff = timeLocal - timeServer; //initalize the clock on loading of page window.onload = function () { //set the interval so clock ticks var timeClock = setInterval("TimeTick()", 1000); } //The ticking clock function function TimeTick() { //grab updated time timeLocal = new Date(); //add time difference timeLocal.setMilliseconds(timeLocal.getMilliseconds() - millDiff); document.getElementById("lblserverTime")=timeLocal; This code working fine for me...</x-turndown>

        1 Reply Last reply
        0
        • G G Mariappan a Murugan

          Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan

          J Offline
          J Offline
          joginder banger
          wrote on last edited by
          #4

          I think you know java script is work on client side. I think ajax control will be help you.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups