The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

using server time on website

Discussion in 'cPanel Developers' started by guanaco, Aug 28, 2008.

  1. guanaco

    guanaco Registered

    Joined:
    May 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I have been trying to show the server time on a website... this is the code I am using

    <script type="text/javascript">

    // Current Server Time script (SSI or PHP)- By JavaScriptKit.com (http://www.javascriptkit.com)
    // For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
    // This notice must stay intact for use.

    //Depending on whether your page supports SSI (.shtml) or PHP (.php), UNCOMMENT the line below your page supports and COMMENT the one it does not:
    //Default is that SSI method is uncommented, and PHP is commented:

    //var currenttime = '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' //SSI method of getting server date
    var currenttime = '<? print date("F d, Y H:i:s", time())?>' //PHP method of getting server date

    ///////////Stop editting here/////////////////////////////////

    var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")
    var serverdate=new Date(currenttime)

    function padlength(what){
    var output=(what.toString().length==1)? "0"+what : what
    return output
    }

    function displaytime(){
    serverdate.setSeconds(serverdate.getSeconds()+1)
    var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
    var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())
    document.getElementById("servertime").innerHTML=datestring+" "+timestring
    }

    window.onload=function(){
    setInterval("displaytime()", 1000)
    }

    </script>
    <span id="servertime"></span>

    The problem I am having is that my server time shows something but the website shows an hour ahead. I have set my server time to AMERICA/El Salvador.

    Can anybody help me? is there any other information you need from me? Thanks in advance
     
  2. guanaco

    guanaco Registered

    Joined:
    May 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    nobody knows about this issue? can anybody help me please.
     
  3. capoti

    capoti Active Member

    Joined:
    Mar 25, 2006
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    contact the author of this javascript or write to JavaScriptKit.com for help.
     
  4. guanaco

    guanaco Registered

    Joined:
    May 18, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    I dont think the scrip is wrong... I have also use the PHP code "<? print date("F d, Y H:i:s", time())?>" and is showing the exact same time than the script... that means an hour ahead of the server time.
     
Loading...

Share This Page