PDA

View Full Version : How can I Create a display digital clock with GMT + 8 to display for all??



johnwboyd
08-11-2008, 08:33 AM
I like this format but I scoured the web and found no solution for this. The closest I found was this confusing and containing extra times I don't want page: http://www.developer.com/lang/article.php/640011

And this one seems like it may work but there are NO instructions about what to do with the code or how to input the HTML! :(
http://www.crays.com/jsc/jsC4Udate.htm#DateTime

I just want a text only 12 hour format wherever viewed: GMT +8 (Manila time)
Such as: 12:22am

That's it!

Thanks in advance.

jscheuer1
08-11-2008, 02:19 PM
You're in luck! There is no DST in Manila. That makes it so much easier:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Manila Time</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<span>Time in Manila - <span id="manilatime">&nbsp;</span></span>
<script type="text/javascript" defer>
;(function(){
var getManilaTime = function(){
var d = new Date(), h, m, s, ampm;
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
d.setHours(d.getHours() + 8);
h = d.getHours();
m = d.getMinutes();
s = d.getSeconds();
ampm = h > 11? 'pm' : 'am';
h = h%12 || 12;
document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ':' + s + ampm;
}
getManilaTime();
setInterval(getManilaTime, 1000);
})();
</script>
</body>
</html>

johnwboyd
08-12-2008, 05:38 AM
I removed the seconds and got the font clean for my layout: www.NegrosChristianChurch.info

jscheuer1
08-12-2008, 06:00 AM
I think you are going to want to add one little bit to the code:


;(function(){
var getManilaTime = function(){
var d = new Date(), h, m, ampm;
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
d.setHours(d.getHours() + 8);
h = d.getHours();
m = d.getMinutes();
m = m.toString(10).length < 2? '0' + m : m;
ampm = h > 11? 'pm' : 'am';
h = h%12 || 12;
document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ampm;
}
getManilaTime();
setInterval(getManilaTime, 1000);
})();

That will make minute values less than 10 pad with a zero:

00
01
02
03

etc.

johnwboyd
08-12-2008, 10:05 AM
Now we're talking! : ) You're the best you noted that fix before I even replied.

johnwboyd
08-13-2008, 06:37 AM
What if I want to add a space in between the time and pm or am?

jscheuer1
08-13-2008, 06:42 AM
document.getElementById('manilatime').firstChild.nodeValue = h + ':' + m + ' ' + ampm;