You must Sign In to post a response.
  • Category: ASP.NET

    How to Show Server Side Date Time using JavaScript in Asp.Net?

    I am showing Current Date And Time Using javascript in my website. But it showing Client Date and Time. I want to Show Server Side Date and Time using javascript. How it could be Possible?
  • #764399
    Scripting will always run on client side so you will always get client machine date and time. Definitely getting server date is not possible without querying server.
    You can use AJAX to load code behind and get server date, or simply in code behind(.CS) use DateTime.Now class and set date in some hidden fields and get it using JavaScript.
    Another option is to use 'ActiveXObject' you can check it on below link

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764416

    If you want server time, then make it one hidden field and assign the datetime to that hiddenfield and call that hidden field data in client side script.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #764417
    But I want to show it like a digital cloak where the time will always change.
    If you are unable to do something properly for the first time, call it Version 1.0!

    Thanks & Regards,

  • #764443
    You can try to given code snippet as guideline to Show Server Side Date Time using JavaScript in Asp.Net

    <script type="text/javascript">
    var serverDateTime = new Date('<%= DateTime.Now.AddHours(1).ToString() %>');
    var dif = serverDateTime - new Date();

    function updateTime()
    var label = document.getElementById("timelabel");
    if (label) {

    var time = (new Date() + dif);
    label.innerHTML = time;
    window.setInterval(updateTime, 1000);

  • Sign In to post your comments