To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-30-2006, 06:07 AM   #1
miha
Member
 
Join Date: Sep 2005
Posts: 48
Changing Time every minut not second

I have JavaScript code and each city time should change evary minut but not with clients PC time but with server time with PHP. Do you have any suggestions?

Code for time is:


HTML Code:
<!-- ############################## -->
<!-- ##### Start of HTML Code ##### -->

<table border="0" cellspacing="2" cellpadding="0" class="worldTimeTable" style="border-style: solid; border-color: #A0A0A0; border-width: 1px;">
	<tr>
		<td id="FrankfurtDT" class="worldTimeTable"></td>
		<td width="10"></td>
		<td id="TokyoDT" class="worldTimeTable"></td>
	</tr>
</table>
<!-- ##### End of HTML Code ##### -->
<!-- ############################ -->


<!-- #################################### -->
<!-- ##### Start of JavaScript Code ##### -->

<script language="JavaScript">
var timerID ;
function tzone(tz, os, ds, cl)
{
	this.ct = new Date(0) ;		// datetime
	this.tz = tz ;		// code
	this.os = os ;		// GMT offset
	this.ds = ds ;		// has daylight savings
	this.cl = cl ;		// font color
}

function UpdateClocks()
{
	var ct = new Array(

		new tzone('<b>Frankfurt:</b> ',  1, 1, ''),
		new tzone('<b>Tokyo:</b> ',  +9, 0, '')
	) ;

	var dt = new Date() ;	// [GMT] time according to machine clock
	var startDST = new Date(dt.getFullYear(), 3, 1) ;
	while (startDST.getDay() != 0)
		startDST.setDate(startDST.getDate() + 1) ;

	var endDST = new Date(dt.getFullYear(), 9, 31) ;
	while (endDST.getDay() != 0)
		endDST.setDate(endDST.getDate() - 1) ;

	var ds_active ;		// DS currently active
	if (startDST < dt && dt < endDST)
		ds_active = 1 ;
	else
		ds_active = 0 ;

	// Adjust each clock offset if that clock has DS and in DS.
	for(n=0 ; n<ct.length ; n++)
		if (ct[n].ds == 1 && ds_active == 1) ct[n].os++ ;

	// compensate time zones
	gmdt = new Date() ;
	for (n=0 ; n<ct.length ; n++)
		ct[n].ct = new Date(gmdt.getTime() + ct[n].os * 3600 * 1000) ;


	document.getElementById("FrankfurtDT").innerHTML = ct[4].tz + ClockString(ct[4].ct);
	document.getElementById("TokyoDT").innerHTML = ct[5].tz + ClockString(ct[5].ct);

	timerID = window.setTimeout("UpdateClocks()", 60000) ;
}

function ClockString(dt)
{
	var stemp, ampm ;
	var dt_year = dt.getUTCFullYear() ;
	var dt_month = dt.getUTCMonth() + 1 ;
	var dt_day = dt.getUTCDate() ;
	var dt_hour = dt.getUTCHours() ;
	var dt_minute = dt.getUTCMinutes() ;
	dt_year = dt_year.toString() ;

	if (dt_minute < 10)
		dt_minute = '0' + dt_minute ;
	if (dt_hour < 10)
		dt_hour = '0' + dt_hour ;

	stemp = getMonthText(dt_month) + ' ' + dt_day + ' ' ;
	stemp = stemp + ' ' + dt_hour + ":" + dt_minute ;
	return stemp ;
}

function getMonthText(tempMon)
{
	switch (tempMon)
	{
		case 1: return "Jan"; break;
		case 2: return "Feb"; break;
		case 3: return "Mar"; break;
		case 4: return "Apr"; break;
		case 5: return "May"; break;
		case 6: return "Jun"; break;
		case 7: return "Jul"; break;
		case 8: return "Aug"; break;
		case 9: return "Sep"; break;
		case 10: return "Oct"; break;
		case 11: return "Nov"; break;
		case 12: return "Dec"; break;
	}
}
UpdateClocks();
</script>
<!-- ##### End of JavaScript Code ##### -->
miha is offline   Reply With Quote
Old 03-30-2006, 07:16 AM   #2
TF@TheMoon
Knights of the Magical Li
 
TF@TheMoon's Avatar
 
Join Date: Mar 2006
Posts: 109
You want the client side code to referesh from data on the server without refreshing the page? You'll need to use xmlHttpRequest.

I, personally, use AJAX and the prototype.js script, as that is what they build into Ruby on Rails, but for what you want its probably overkill.

This might be a good read to start http://www.xml.com/pub/a/2005/02/09/...p-request.html

But google on xmlHttpRequest for other.

Basically you'l need your Javascript to trigger the xmlHttpRequest ever minute that calls a PHP script that simply returns the server time. this wil then be picked up by your javascript code to do with as it wants
TF@TheMoon is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:40 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.