1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <?php
function getTimeZone()
{
$timeZone = DateTimeZone::listIdentifiers();
$option = '';
foreach($timeZone as $nom)
{
$option .= '<option value="' . $nom . '">' . $nom . '</option>' . "\n";
}
return $option;
}
function heureLocale()
{
$tmp = new DateTime();
$dateLocale = $tmp -> format('d/m/Y');
$heureLocale = $tmp -> format('H:i:s');
return 'Nous sommes le ' . $dateLocale . ' et il est ' . $heureLocale . ' heure locale';
}
function heureDistante()
{
if(! isset($_POST['fuseau']))
{
return 'non défini';
}
$tmp = new DateTime();
$offset = $tmp -> format('Z') * -1;
$tmp -> modify($offset . ' second');
$dateTimeZone = new DateTimeZone($_POST['fuseau']);
$offset = $dateTimeZone -> getOffset($tmp);
$tmp -> modify($offset . ' second');
$dateDistante = $tmp -> format('d/m/Y');
$heureDistante = $tmp -> format('H:i:s');
return 'A ' . $_POST['fuseau'] . ', c\'est le ' . $dateDistante . ' et il est ' . $heureDistante;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">
<title></title>
</head>
<body>
<form method="post" name="test" action="">
<select name="fuseau">
<option value="">Sélectionnez un pays</option>
<?php echo getTimeZone(); ?>
</select>
<br>
<input type="submit" name="btn">
</form>
<br>
<?php echo heureLocale(); ?>
<br>
<?php echo heureDistante() ?>
</body>
</html> |