Page 1 of 1

Daylight savings time and the system clock

Posted: Mon Jul 21, 2008 7:02 am
by craiglindley
I wasn't sure where to post this question so I posted it to both locations.

I'm using a stock MOD-5270 module for my web server application which means no RTC chip. Instead I'm using the system clock for my purposes. My question is if I set the use daylight saving flag in the time calls will the system clock adjust itself accordingly when the time changes? I think the answer is no but I want to be sure.

Craig Lindley

Re: Daylight savings time and the system clock

Posted: Mon Jul 21, 2008 11:08 am
by rnixon
Hi Craig,

I think the answer is no. Have you looked into adding a RTC on your board?

Re: Daylight savings time and the system clock

Posted: Wed Sep 03, 2008 12:23 pm
by Brian Click
This is an old thread but...

You could call a JS function, to get the user's PC timezone, through the browser, into form elements (or other DOM objects just the same):

Code: Select all

function getpctime() 
{
	var t = new Date();
	document.my_form.GMT_OFFSET.value = (t.getTimezoneOffset()/60)*-1; //timezone according to PC
}
and apply that offset to all displayed times in your UI. That way users anywhere will see the correctly adjusted time.

I assume you're "occasionally" getting the correct time from a NTP server, to sync the system clock. If you're using the user's PC clock to sync the NB system clock, then you can do it all within the same function, by fleshing it out, something like this:

Code: Select all

function getpctime() 
{
	var t = new Date();

	document.my_form.YEAR.value = t.getFullYear();
	document.my_form.MONTH.value = fixNumber( t.getMonth() +1);	//  January is month 0
	document.my_form.DAY.value = fixNumber( t.getDate() );
	document.my_form.HOUR.value = fixNumber( t.getHours() );
	document.my_form.MINUTE.value = fixNumber( t.getMinutes() );
	document.my_form.SECOND.value = fixNumber( t.getSeconds() );
	document.my_form.GMT_OFFSET.value = (t.getTimezoneOffset()/60)*-1;
}

//need this function too
function fixNumber(the_number)
{
	if (the_number < 10)
	{
		the_number = "0" + the_number;
	}
	return the_number;
}
hope it helps someone