SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question help displaying Hawaii time zone in contact page

    I have a client in Hawaii who offering a few books for sale on his website. He wants to post his local time on the contact page, along with his phone number and office hours. The idea is that people will see it is too early or late to call.

    I am not Javascript savy, so I am seeking help on the code below. I think my coding effort below is showing the user's browser time, not Hawaii time (which is -10:00 UTC).

    Code:
    <script language="JavaScript">
    var d=new Date(); 
    var n=d.toLocaleTimeString();;
    document.write(n);
    </script>
    After crawling the JS Date Object and Methods I am at a loss at this point. Any one got a minute?
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    A better option is to use PHP. The first question to ask, though, is where the server for the website is located. If it's in Hawaii, that's easier, as you just display the current server time on screen. If the server is located elsewhere, you just need to tweak the time setting first.

  3. #3
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    A better option is to use PHP. The first question to ask, though, is where the server for the website is located. If it's in Hawaii, that's easier, as you just display the current server time on screen. If the server is located elsewhere, you just need to tweak the time setting first.
    I researched the PHP timezone code for Hawaii: Pacific/Honolulu; but the contact page is already HTML. HostMonster is the server owner, phpinfo.php reports Default timezone America/Denver. And Wikipedia reports MST -7 UTC and (daylight saving) MDT -6 UTC.

    My thoughts are: get UTC time and subtract 10 hours. JS Date Methods: getUTCHours() and getUTCMinutes() and getUTCSeconds() seem to be the only way to get the UTC time.
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by gregorious View Post
    the contact page is already HTML.
    If you want to use PHP, you could make it a PHp page instead and do an htaccess redirect from the old page to the new.

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hawaii is one of the simplest places to work with time zones,
    no daylight savings adjustments are needed.

    This example keeps the Hawiian time string updated
    by checking the local time every 5 seconds,
    and changing the display when the minutes change.

    Code:
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset= "utf-8">
    <title>Hawaiian time</title>
    
    <script>
    var hitimer;
    function getHiTime(){
    	var days= ['Sunday', 'Monday', 'Tuesday',
    	'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    	h, m, mod, now= new Date();
    	now.setUTCHours(now.getUTCHours()-10);
    
    	h= now.getUTCHours();
    	mod= h<12? " am":" pm";
    	if(h>12) h -= 12;
    	else if(h== 0) h= 12;
    
    	m=now.getUTCMinutes()+'';
    	while(m.length<2)m+='0';
    	return days[now.getUTCDay()]+ ' '+ h+ ':'+ m+ mod;
    }
    
    function showHiTime(){
    	var who= document.getElementById('HiTime'),
    	say= who.firstChild.data,
    	when= getHiTime();
    
    	if(say!= when) who.firstChild.data= when;
    }
    window.onload=function(){
    	showHiTime();
    	hiTimer= setInterval(showHiTime, 5000);
    }
    </script>
    
    </head>
    <body>
    
    <h3>Hawaiian standard time: <span id="HiTime">(GMT-10 hours)</span></h3>
    
    </body>
    </html>
    Last edited by mrhoo; Oct 3, 2012 at 08:10. Reason: padded minutes


Bookmarks

Posting Permissions

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