format('T'); return str_starts_with($offset, '-') || str_starts_with($offset, '+') ? 'UTC' . $offset : $offset; } function toTZ($dt, $tz, $format='Y-m-d H:i') { $tz = new DateTimeZone($tz); return $dt->setTimezone($tz)->format($format); } function setUserCookie($name, $value) { setcookie($name, $value, time() + COOKIE_LIFETIME, '/'); $_COOKIE[$name] = $value; } $popTZ = [ 'America/Los_Angeles', // PST/PDT 'America/New_York', // EST/EDT 'Europe/London', // BST/GMT 'Europe/Paris', // CEST/CET 'Asia/Dubai', // UTC+04 "UAE" 'Asia/Jakarta', // WIB 'Asia/Tokyo', // JST 'Australia/Sydney', // AEST/AEDT 'UTC' ]; $allTZ = timezone_identifiers_list(DateTimeZone::ALL); // User sets timezone cookie if (isset($_POST['user-tz']) && in_array($_POST['user-tz'], $allTZ)) { setUserCookie('user-tz', $_POST['user-tz']); } // User sets 24 hours if (isset($_POST['user-24'])) { setUserCookie('user-24', '1'); } // If had JS enabled but doesn't now, set has-js to 0 if (isset($_POST['no-js'])) { setUserCookie('has-js', '0'); } // Micro-routing try { if (isset($_POST['datetime']) && isset($_POST['timezone'])) { // -- Redirect to submitted date // @NOTE(Kody): I'm fine not validating all inputs here. // Either it will fall in the catch block, or fail at the validation after the redirect. // Handle if timezone is an offset $postTZ = $_POST['timezone']; if (is_numeric($_POST['timezone'])) { $isNeg = str_starts_with($postTZ, '-'); $h = str_pad(abs(intdiv($postTZ, 60)), 2, '0', STR_PAD_LEFT); $m = str_pad($postTZ % 60, 2, '0', STR_PAD_LEFT); $postTZ = ($isNeg ? '-' : '+') . $h . $m; } // Make our date object $dateObj = new DateTime($_POST['datetime'], new DateTimeZone($postTZ)); // Redirect, with the "+" replaced by "_" header('Location: /' . str_replace('+', '_', $dateObj->format('c'))); exit; } elseif ($_SERVER['REQUEST_URI'] !== '/') { // -- Show date infos // Remove leading "/" $req = substr($_SERVER['REQUEST_URI'], 1); // Check if date is following the format $re = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\_|-]\d{2}:\d{2}$/'; if (!preg_match($re, $req)) { http_response_code(404); $error = 'Date is not valid, wrong format, or file not found.'; } else { // Make our date object, convert back "_" to "+" $dt = new DateTime(str_replace('_', '+', $req)); } } } catch (Exception $e) { http_response_code(400); $error = 'Date is not valid, or wrong format.'; } ?> Time Zones Are Hard<?= isset($req) ? ' - ' . htmlspecialchars(str_replace('_', '+', $req), ENT_QUOTES, 'UTF-8') : '' ?>

Time Zones Are Hard

Error:


In popular time zones


Fill out this form to make a page that shows a set date and time in the visitor's time zone.
It will also show the time in other popular time zones.