calculate time different

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
roice
Forum Commoner
Posts: 35
Joined: Tue Mar 02, 2010 9:14 am

calculate time different

Post 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.
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: calculate time different

Post 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.
smithdwsn
Forum Newbie
Posts: 3
Joined: Tue Jun 01, 2010 1:53 pm

Re: calculate time different

Post 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.
Post Reply