------------------------------------------------------
Earth | Time | Date |
------------------------------------------------------
-Silicon Valley | <?php timeEarth(-8) ?> | <?php dateEarth(-8) ?> |
-Boston | <?php timeEarth(-5) ?> | <?php dateEarth(-5) ?> |
-London* | <?php timeEarth(0) ?> | <?php dateEarth(0) ?> |
-Tokyo | <?php timeEarth(9) ?> | <?php dateEarth(9) ?> |
+Silicon Valley | <?php timeEarth("America/Los_Angeles") ?> | <?php dateEarth("America/Los_Angeles") ?> |
+Boston | <?php timeEarth("America/New_York") ?> | <?php dateEarth("America/New_York") ?> |
+London* | <?php timeEarth("Europe/London") ?> | <?php dateEarth("Europe/London") ?> |
+Tokyo | <?php timeEarth("Asia/Tokyo") ?> | <?php dateEarth("Asia/Tokyo") ?> |
------------------------------------------------------
Mars | Time | Date |
//echo "Data valid to time: ". $current_time . "<br>";
}
- function timeEarth($offset) {
-
- $dateTime = new DateTime("now", new DateTimeZone("UTC"));
-
- // Modify the timezone using the provided offset
- $timezoneName = sprintf("Etc/GMT%+d", -$offset);
- $dateTime->setTimezone(new DateTimeZone($timezoneName));
-
- // Print the formatted time
- echo $dateTime->format("H:i");
-
+function timeEarth($timezone) {
+ try {
+ $dateTime = new DateTime("now", new DateTimeZone($timezone));
+ echo $dateTime->format("H:i");
+ } catch (Exception $e) {
+ echo "Invalid timezone provided.";
+ }
}
- function dateEarth(int $offset) {
- // Create a DateTime object for the current date
- $dateTime = new DateTime("now", new DateTimeZone("UTC"));
-
- // Modify the timezone using the provided offset
- $timezoneName = sprintf("Etc/GMT%+d", -$offset);
- $dateTime->setTimezone(new DateTimeZone($timezoneName));
-
- // Print the formatted date
- echo $dateTime->format("d-m(M)-Y");
+function dateEarth($timezone) {
+ try {
+ $dateTime = new DateTime("now", new DateTimeZone($timezone));
+ echo $dateTime->format("d-m(M)-Y");
+ } catch (Exception $e) {
+ echo "Invalid timezone provided";
+ }
}
function get_time_m(){