Sorry if this is not the appropriate forum. Experienced PHP developers, please advise:
My server is in Kansas (Central time). Right now, due to DST, we are
GMT -5...in the Winter GMT -6
my form gives users the option to select a date, time, and timezone
for a specific event to occur. So, say the user is in California and
they choose 8:00AM, January 1st 2011, Pacific Time (2 hours behind
us).
Well, I want my script to take the date, time, and timezone they
choose and convert it to central time so I can timestamp it on my
server ... so for this example, I'd timestamp the file 10:00AM,
January 1st 2011 ... then on that date, the event would occur at
10:00AM my time, 8:00AM their time.
I've got some code that is getting close to accomplishing this....do
you have any experience with timezone stuff?
my code:
$userTimezone = new DateTimeZone($tz);
$myDateTime = new DateTime($time);
$cstTimeZone = new DateTimeZone('CST');
$myDateTime = new DateTime($time, $userTimezone);
echo $myDateTime->format('r'); // browser prints this: Sat, 01 Jan
2011 08:00:00 -0800
$offset = $cstTimeZone->getOffset($myDateTime);
echo "<br />";
echo $offset; // browser prints this: -21600
echo "<br />";
echo date('Y-m-d H:i:s', $myDateTime->format('U') + $offset); //
browser prints this: 2011-01-01 04:00:00
echo "<br />";
so, the first echo is correct...it prints the date and time the user
chose ... plus the GMT time
I'm going off of an article I found here(
http://blog.boxedice.com/
2009/03/21/handling-timezone-conversion-with-php-datetime/), but I
must be doing something wrong b/c the last echo certainly doesn't
print out the correct time I'm looking for.