Hello everybody,
First off let me say I did do a search of google and these forums before posting this. I have sort of what I want without having exactly what I want and before I proceed further hacking up already working code I figured I'd start a conversation as to whether my goal is at all possible.

Currently using (thank you w3schools as I am by no means a javascript expert):

document.writeln(new Date())

I get the following: Wed Jul 13 2011 09:24:09 GMT-0600 (Mountain Daylight Time)
which would be great for most people, but I'm kind of picky so I want the clock to keep ticking and to show the current time.

To do this I use this code(again thank you w3schools):

function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}

function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

This displays: 09:24:09.

Now for the question is it possible to hack up the

document.writeln(new Date())

to display as follows:
09:24:09 (Mountain Daylight Time)

with the time being that of my clock? Or am I going to be forced to learn javascript and create my own script that gets the time, checks the timezone and converts it to MST for example?

Also while we are on the topic of formatting can that Mountain Daylight Time be formatted to be MDT/MST?

This is the fastest and shortest I can do for you:
(The MDT/MST will depend on your clock settings. If you've chosen MST, MST display it will!)

<!DOCTYPE native>
<html>
<head>
<title>Live Clock</title>
   <style>
	div
	{
		background-color: silver;
		border: 1px solid gray;
		padding: 1px 5px;
		border-radius: 4px;
	}
   </style>
</head>
<body>
<div>
	Time: &nbsp; <input id="time">
</div>
<script>
onload=
	liveClock=
		function(){
		var tm = Date();
			tm=(tm.toString()).split(' ');
			time.value = tm[3]+" "+tm[4];
		setTimeout("liveClock()", 500);
	}
</script>
</body>
</html>

Thank you Troy and sorry for taking so long to post back, what I ended up doing was this:

echo '<script type="text/javascript">
						function startTime()
							{
							var today=new Date();
							var h=today.getHours();
							var m=today.getMinutes();
							var s=today.getSeconds();
							// add a zero in front of numbers<10
							m=checkTime(m);
							s=checkTime(s);
							document.getElementById("time").innerHTML=h+":"+m+":"+s;
							t=setTimeout("startTime()",500);
							}

							function checkTime(i)
							{
							if (i<10)
								{
								i="0" + i;
								}
							return i;
						}
						</script>';
						
						echo'<div id="time">&nbsp;</div>';

Which outputs: Hour:Minute:Second

Followed by:

echo'<div id="tz">[
						<script type="text/javascript">
							var rightNow = new Date();
							document.write(String(String(rightNow).split("(")[1]).split(")")[0]);
						</script>&nbsp;]
					</div>';

Which outputs the timezone inbetween [ ]. Only problem is it doesn't always show the timezone depending on if the person is hiding behind a proxy. Your way seems alot simpler but as I explained in a PM I was a bit tied up in real life.

well, this is all wrong, and it doesn't have to do anything with hiding behind a proxy or not.

Ya I'm no javascript expert but it works. And it might look a bit weird cause I have it embedded in a php page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.