Page 1 of 1

calculate time different

Posted: Sun May 09, 2010 5:00 am
by roice
hello,
I have problem with JS and I'm hoping you will be able to help me.
I built 2 steps script - in the first page the visitor choose the date he want to schedual his appoitment and his location:

Code: Select all

<select name='zone'>
							<option value='-4' selected> USA - EST</option>
							<option value='-7'>USA - PST</option>
							<option value='-5'>USA - CST</option>
							<option value='+8'>Austrlia - East Coast</option>
						</select>
In the second page he need to choose the time he want for his appointment (the time is in GMT+3 -> my local time). in this page the script also get the time zone and the date that he choose in the previous page (using POST - PHP). the date saved in variable. I used unix time (MKTIME function)

I want that every time my visitor choose time (from drop-down box) a new cell/DIV will appear with his local time.
for example - when he choose date: 10 May 2010, time zone: Austrlia - East Coast (+8 Hours) and time 22:00, New DIV will appear with the date "11 May 2010, 03:00AM" (there are 5 hours different).

what is the JS what caculate and show the visitor local time?
(I have, in PHP, only his time zone and the date that he coose in the first page)

Thanks in advance,
Roi.

Re: calculate time different

Posted: Sun May 09, 2010 6:10 am
by roice

Re: calculate time different

Posted: Thu May 13, 2010 1:40 pm
by ell0bo
Javascript will only be able to tell you the time local to the user's computer. You can actually get the timezone by (newDate()).getTimezoneOffset() and then using the offset to figure out what timezone they are in.

Now, knowing that you can then calculate the other dates by just doing the math of the difference between timezone offsets.

Re: calculate time different

Posted: Thu Jun 03, 2010 8:44 am
by smithdwsn
You can use get_time_difference() function.
Syntax : array get_time_difference( string start, string end )
This function requires start and end date. These strings will be converted to Unix timestamps before the function works with them. Unix timestamp is January 1, 1970 00:00:00 GMT.