Skip to content

Instantly share code, notes, and snippets.

@tegaphilip
Created November 7, 2017 22:11
Show Gist options
  • Save tegaphilip/65efaba057c34ed3f2622db6c13882c4 to your computer and use it in GitHub Desktop.
Save tegaphilip/65efaba057c34ed3f2622db6c13882c4 to your computer and use it in GitHub Desktop.
<?php
if (isset($_GET['offset'])) {
echo 'Your current timezone is ' . timezone_name_from_abbr('', $_GET['offset'] * 60, false);
exit;
}
?>
<html>
<head>
<title>MY TIMEZONE</title>
</head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var timezone_offset_minutes = new Date().getTimezoneOffset();
timezone_offset_minutes = timezone_offset_minutes === 0 ? 0 : -timezone_offset_minutes;
$.ajax({
type: 'GET',
url: window.location.href + '?offset=' + timezone_offset_minutes,
success: function (response) {
$('#timezone').html(response);
},
error: function (e) {
alert('fail');
console.log(e.responseText);
}
});
});
</script>
<body>
<div id="timezone"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment