I am working on code to automatically detect a users timezone and then adjust the timestamps to reflect their timezone.
Here is a small JavaScript that will return the users current timezone.
[CODE]<script src=’http://code.jquery.com/jquery-2.1.1.js’></script>
<script src=”jstz.min.js”></script>
<script>
$(document).ready(function(){
var timezone = jstz.determine();
document.write(timezone.name());
});
</script>
This will return for me “America/New_York”.
I need to somehow get the users timezone from this javascript and put it into a variable in PHP to be read by the script below.
[code=php]<?php
// Date & time format.
$date_format = “m/d/Y”;
$time_format = “h:i A”;
// Set timezone.
$timezone = “America/New_York”;
// Get current datetime.
$date = new DateTime();
// Set timezone.
$date->setTimezone(new DateTimeZone($timezone));
// Echo current date and time.
echo $date->format($date_format . ” ” . $time_format);
?>
Can anyone help explain to me how I can do this?