gregorious — 2012-09-29T03:21:03-04:00 — #1
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.
var d=new Date();
After crawling the JS Date Object and Methods I am at a loss at this point. Any one got a minute?
ralphm — 2012-09-29T05:32:16-04:00 — #2
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.
gregorious — 2012-09-30T04:41:22-04:00 — #3
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.
ralphm — 2012-09-30T09:14:28-04:00 — #4
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.
mrhoo — 2012-10-03T10:52:56-04:00 — #5
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.
<meta charset= "utf-8">
var days= ['Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday'],
h, m, mod, now= new Date();
mod= h<12? " am":" pm";
if(h>12) h -= 12;
else if(h== 0) h= 12;
return days[now.getUTCDay()]+ ' '+ h+ ':'+ m+ mod;
var who= document.getElementById('HiTime'),
if(say!= when) who.firstChild.data= when;
hiTimer= setInterval(showHiTime, 5000);
<h3>Hawaiian standard time: <span id="HiTime">(GMT-10 hours)</span></h3>