Previously it was only posiable to use the browers default timezone. To be done: Add more timezones to the list of possiable ones. Clean up the formating of the updating clock to match the php generated inishal date string.
67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<!DOCTYPE html>
|
|
<?php
|
|
/* Catches the form post to update the timezone.
|
|
* If there is no form submission it will just inishilize the
|
|
* timezone variables to be passed to the JS.
|
|
*/
|
|
if(isset($_POST['formSubmit'])){
|
|
$selectedTimezone = $_POST['userTimezone'];
|
|
if(!isset($selectedTimezone)){
|
|
//I don't have any error message set here. It will just reload the page.
|
|
} else{
|
|
date_default_timezone_set($selectedTimezone);
|
|
$scriptTZ = date_default_timezone_get();
|
|
}
|
|
} else{
|
|
$selectedTimezone = date_default_timezone_get();
|
|
//date_default_timezone_set("America/Los_Angeles");
|
|
$scriptTZ = date_default_timezone_get();
|
|
}
|
|
?>
|
|
<html>
|
|
<head>
|
|
<title id='time_title'>
|
|
<?php
|
|
echo "Time is: " . date("H:i:s e");
|
|
?>
|
|
</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<meta name="author" content="efrick"/>
|
|
<link href="/styles.css" type="text/css" rel="stylesheet"/>
|
|
<script>var current_tz=<?php echo json_encode($scriptTZ);?></script>
|
|
<script type="text/javascript" src="clock.js"></script>
|
|
</head>
|
|
<body>
|
|
<h1>
|
|
Date and Time
|
|
</h1>
|
|
<div class="body">
|
|
<?php //Print default time and date values for the JS to update.
|
|
echo "The full date and time:".
|
|
"<br>".
|
|
"<p id='time_body'>".
|
|
date("D M d Y H:i:s") .
|
|
" GMT" . date("O") . " (" . date("T") . ")"."</p>\n\t\t";
|
|
echo '<p>The user timezone is now set to ' . $selectedTimezone . "</p>\n\t\t";
|
|
echo '<p>The system timezone is now set to ' . $scriptTZ . "</p>\n";
|
|
?>
|
|
<div class="tz_select">
|
|
<p>
|
|
If the detcted timezone is not correct selct your timezone from the dropdown below.
|
|
</p>
|
|
</div>
|
|
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
|
|
<select name="userTimezone" class="tz_select">
|
|
<option value="" disabled selected class="invisable">Timezone</option>
|
|
<option value="EDT">EDT</option>
|
|
<option value="UTC">UTC</option>
|
|
<option value="America/Los_Angeles">PDT</option>
|
|
</select><br/>
|
|
<input type="submit" name="formSubmit" value="Update" >
|
|
</form>
|
|
<p id="JStz">JS Timezone</p>
|
|
</div>
|
|
</body>
|
|
</html>
|