Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><head><base href="https://example.com">
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>World Clock</title>
- <style>
- body {
- font-family: 'Arial', sans-serif;
- margin: 0;
- background-color: #f7f7f7;
- color: #333;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 20px;
- transition: background-color 0.3s, color 0.3s;
- }
- body.dark-mode {
- background-color: #333;
- color: #f7f7f7;
- }
- #header {
- text-align: center;
- margin-bottom: 20px;
- }
- h1 {
- color: #333;
- margin: 0;
- transition: color 0.3s;
- }
- body.dark-mode h1 {
- color: #f7f7f7;
- }
- #header-details {
- text-align: center;
- color: #777;
- font-size: 14px;
- margin-bottom: 10px;
- transition: color 0.3s;
- }
- body.dark-mode #header-details {
- color: #bbb;
- }
- #search-container {
- margin-bottom: 20px;
- width: 80%;
- max-width: 600px;
- display: flex;
- gap: 10px;
- }
- #search-bar {
- padding: 12px;
- border: 1px solid #ddd;
- border-radius: 8px;
- font-size: 16px;
- width: calc(100% - 24px);
- outline: none;
- box-shadow: 0 2px 4px rgba(0,0,0,0.05);
- flex-grow: 1;
- background-color: #fff;
- color: #333;
- transition: background-color 0.3s, color 0.3s, border-color 0.3s;
- }
- body.dark-mode #search-bar {
- background-color: #444;
- color: #eee;
- border-color: #555;
- }
- #settings-button {
- padding: 12px 16px;
- border: 1px solid #ddd;
- border-radius: 8px;
- background-color: #fff;
- color: #333;
- cursor: pointer;
- font-size: 14px;
- box-shadow: 0 2px 4px rgba(0,0,0,0.05);
- transition: background-color 0.3s, color 0.3s, border-color 0.3s;
- }
- body.dark-mode #settings-button {
- background-color: #444;
- color: #eee;
- border-color: #555;
- }
- #settings-button:hover {
- background-color: #f0f0f0;
- }
- body.dark-mode #settings-button:hover {
- background-color: #555;
- }
- #countries-container {
- width: 80%;
- max-width: 800px;
- background-color: #fff;
- border-radius: 12px;
- box-shadow: 0 4px 8px rgba(0,0,0,0.05);
- overflow: hidden;
- transition: background-color 0.3s;
- }
- body.dark-mode #countries-container {
- background-color: #444;
- }
- .country-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 16px 20px;
- border-bottom: 1px solid #eee;
- transition: background-color 0.3s ease, border-color 0.3s;
- }
- body.dark-mode .country-item {
- border-bottom-color: #555;
- }
- .country-item:last-child {
- border-bottom: none;
- }
- .country-item:hover {
- background-color: #f9f9f9;
- }
- body.dark-mode .country-item:hover {
- background-color: #555;
- }
- .country-name {
- font-weight: bold;
- color: #333;
- transition: color 0.3s;
- }
- body.dark-mode .country-name {
- color: #eee;
- }
- .country-details {
- display: flex;
- align-items: center;
- }
- .country-time {
- font-size: 18px;
- color: #555;
- margin-right: 10px;
- position: relative;
- display: flex;
- align-items: center;
- transition: color 0.3s;
- }
- body.dark-mode .country-time {
- color: #ccc;
- }
- .country-date {
- font-size: 14px;
- color: #777;
- margin-right: 10px;
- transition: color 0.3s;
- }
- body.dark-mode .country-date {
- color: #bbb;
- }
- .country-timezone {
- font-size: 14px;
- color: #999;
- transition: color 0.3s;
- }
- body.dark-mode .country-timezone {
- color: #999;
- }
- .loading-spinner {
- width: 16px;
- height: 16px;
- border: 2px solid rgba(0, 0, 0, 0.1);
- border-left-color: #007BFF;
- border-radius: 50%;
- animation: spin 1s linear infinite;
- margin-left: 8px;
- }
- @keyframes spin {
- to { transform: rotate(360deg); }
- }
- .hidden {
- display: none;
- }
- .clock-icon {
- width: 16px;
- height: 16px;
- margin-right: 4px;
- fill: currentColor;
- }
- #settings-container {
- width: 80%;
- max-width: 800px;
- background-color: #fff;
- border-radius: 12px;
- box-shadow: 0 4px 8px rgba(0,0,0,0.05);
- overflow: hidden;
- margin-top: 20px;
- padding: 20px;
- transition: background-color 0.3s;
- }
- body.dark-mode #settings-container {
- background-color: #444;
- }
- #settings-container h2 {
- color: #333;
- margin-top: 0;
- margin-bottom: 15px;
- transition: color 0.3s;
- }
- body.dark-mode #settings-container h2 {
- color: #eee;
- }
- .setting-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 10px 0;
- border-bottom: 1px solid #eee;
- transition: border-color 0.3s;
- }
- body.dark-mode .setting-item {
- border-bottom-color: #555;
- }
- .setting-item:last-child {
- border-bottom: none;
- }
- .setting-label {
- font-weight: bold;
- color: #555;
- transition: color 0.3s;
- }
- body.dark-mode .setting-label {
- color: #ccc;
- }
- .timezone-details {
- font-size: 12px;
- color: #666;
- margin-top: 4px;
- transition: color 0.3s;
- }
- body.dark-mode .timezone-details {
- color: #999;
- }
- .utc-offset {
- font-size: 12px;
- color: #888;
- margin-left: 8px;
- transition: color 0.3s;
- }
- body.dark-mode .utc-offset {
- color: #777;
- }
- .country-population {
- font-size: 12px;
- color: #666;
- margin-top: 2px;
- transition: color 0.3s;
- }
- body.dark-mode .country-population {
- color: #999;
- }
- .last-updated {
- font-size: 11px;
- color: #999;
- margin-top: 4px;
- font-style: italic;
- transition: color 0.3s;
- }
- body.dark-mode .last-updated {
- color: #777;
- }
- </style>
- </head>
- <body>
- <div id="header">
- <h1>World Clock</h1>
- <div id="header-details">
- <span id="local-date"></span> - <span id="local-time"></span>
- </div>
- </div>
- <div id="search-container">
- <input type="text" id="search-bar" placeholder="Search for a country...">
- <button id="settings-button">
- <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0 1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
- </button>
- </div>
- <div id="countries-container">
- <!-- Country items will be added here by JavaScript -->
- </div>
- <div id="settings-container" class="hidden">
- <h2>Settings</h2>
- <div class="setting-item">
- <span class="setting-label">Show Seconds</span>
- <input type="checkbox" id="show-seconds">
- </div>
- <div class="setting-item">
- <span class="setting-label">Dark Mode</span>
- <input type="checkbox" id="dark-mode-toggle">
- </div>
- </div>
- <script>const body = document.body;
- const countriesContainer = document.getElementById('countries-container');
- const searchBar = document.getElementById('search-bar');
- const settingsContainer = document.getElementById('settings-container');
- const settingsButton = document.getElementById('settings-button');
- const localDateElement = document.getElementById('local-date');
- const localTimeElement = document.getElementById('local-time');
- const showSecondsCheckbox = document.getElementById('show-seconds');
- const darkModeToggle = document.getElementById('dark-mode-toggle');
- let showSeconds = false;
- let darkMode = localStorage.getItem('darkMode') === 'enabled';
- if (darkMode) {}
- const countryPopulations = {
- "United States": "331 million",
- "China": "1.4 billion",
- "India": "1.38 billion",
- "Japan": "125.7 million",
- "Iceland": "364,134",
- "Greenland": "56,421",
- "Faroe Islands": "48,863",
- "Svalbard": "2,667",
- "Jan Mayen": "18"
- };
- function getUTCOffset(timezone) {
- const now = new Date();
- const tzOffset = new Date().toLocaleTimeString('en-US', {
- timeZone: timezone,
- timeZoneName: 'longOffset'
- }).split(' ').pop();
- return tzOffset;
- }
- showSecondsCheckbox.addEventListener('change', () => {
- showSeconds = showSecondsCheckbox.checked;
- renderCountries(countriesTimezones);
- });
- darkModeToggle.addEventListener('change', () => {
- darkMode = darkModeToggle.checked;
- body.classList.toggle('dark-mode', darkMode);
- localStorage.setItem('darkMode', darkMode ? 'enabled' : 'disabled');
- });
- settingsButton.addEventListener('click', () => {
- settingsContainer.classList.toggle('hidden');
- });
- const countriesTimezones = [{
- name: "United States",
- timezone: "America/New_York"
- }, {
- name: "Canada",
- timezone: "America/Toronto"
- }, {
- name: "Brazil",
- timezone: "America/Sao_Paulo"
- }, {
- name: "United Kingdom",
- timezone: "Europe/London"
- }, {
- name: "France",
- timezone: "Europe/Paris"
- }, {
- name: "Germany",
- timezone: "Europe/Berlin"
- }, {
- name: "Japan",
- timezone: "Asia/Tokyo"
- }, {
- name: "China",
- timezone: "Asia/Shanghai"
- }, {
- name: "Australia",
- timezone: "Australia/Sydney"
- }, {
- name: "India",
- timezone: "Asia/Kolkata"
- }, {
- name: "South Africa",
- timezone: "Africa/Johannesburg"
- }, {
- name: "Argentina",
- timezone: "America/Argentina/Buenos_Aires"
- }, {
- name: "Mexico",
- timezone: "America/Mexico_City"
- }, {
- name: "Russia",
- timezone: "Europe/Moscow"
- }, {
- name: "Italy",
- timezone: "Europe/Rome"
- }, {
- name: "Spain",
- timezone: "Europe/Madrid"
- }, {
- name: "Egypt",
- timezone: "Africa/Cairo"
- }, {
- name: "Nigeria",
- timezone: "Africa/Lagos"
- }, {
- name: "New Zealand",
- timezone: "Pacific/Auckland"
- }, {
- name: "South Korea",
- timezone: "Asia/Seoul"
- }, {
- name: "Singapore",
- timezone: "Asia/Singapore"
- }, {
- name: "Ireland",
- timezone: "Europe/Dublin"
- }, {
- name: "Sweden",
- timezone: "Europe/Stockholm"
- }, {
- name: "Norway",
- timezone: "Europe/Oslo"
- }, {
- name: "Denmark",
- timezone: "Europe/Copenhagen"
- }, {
- name: "Finland",
- timezone: "Europe/Helsinki"
- }, {
- name: "Switzerland",
- timezone: "Europe/Zurich"
- }, {
- name: "Netherlands",
- timezone: "Europe/Amsterdam"
- }, {
- name: "Belgium",
- timezone: "Europe/Brussels"
- }, {
- name: "Austria",
- timezone: "Europe/Vienna"
- }, {
- name: "Poland",
- timezone: "Europe/Warsaw"
- }, {
- name: "Ukraine",
- timezone: "Europe/Kiev"
- }, {
- name: "Greece",
- timezone: "Europe/Athens"
- }, {
- name: "Turkey",
- timezone: "Europe/Istanbul"
- }, {
- name: "Saudi Arabia",
- timezone: "Asia/Riyadh"
- }, {
- name: "United Arab Emirates",
- timezone: "Asia/Dubai"
- }, {
- name: "Indonesia",
- timezone: "Asia/Jakarta"
- }, {
- name: "Thailand",
- timezone: "Asia/Bangkok"
- }, {
- name: "Vietnam",
- timezone: "Asia/Ho_Chi_Minh"
- }, {
- name: "Philippines",
- timezone: "Asia/Manila"
- }, {
- name: "Malaysia",
- timezone: "Asia/Kuala_Lumpur"
- }, {
- name: "Portugal",
- timezone: "Europe/Lisbon"
- }, {
- name: "Hungary",
- timezone: "Europe/Budapest"
- }, {
- name: "Czech Republic",
- timezone: "Europe/Prague"
- }, {
- name: "Romania",
- timezone: "Europe/Bucharest"
- }, {
- name: "Bulgaria",
- timezone: "Europe/Sofia"
- }, {
- name: "Croatia",
- timezone: "Europe/Zagreb"
- }, {
- name: "Serbia",
- timezone: "Europe/Belgrade"
- }, {
- name: "Slovakia",
- timezone: "Europe/Bratislava"
- }, {
- name: "Lithuania",
- timezone: "Europe/Vilnius"
- }, {
- name: "Latvia",
- timezone: "Europe/Riga"
- }, {
- name: "Estonia",
- timezone: "Europe/Tallinn"
- }, {
- name: "Iceland",
- timezone: "Atlantic/Reykjavik"
- }, {
- name: "Greenland",
- timezone: "America/Godthab"
- }, {
- name: "Faroe Islands",
- timezone: "Atlantic/Faroe"
- }, {
- name: "Svalbard",
- timezone: "Arctic/Longyearbyen"
- }, {
- name: "Jan Mayen",
- timezone: "Arctic/Longyearbyen"
- }, {
- name: "Cyprus",
- timezone: "Asia/Nicosia"
- }, {
- name: "Malta",
- timezone: "Europe/Malta"
- }, {
- name: "Luxembourg",
- timezone: "Europe/Luxembourg"
- }, {
- name: "Monaco",
- timezone: "Europe/Monaco"
- }, {
- name: "Liechtenstein",
- timezone: "Europe/Vaduz"
- }, {
- name: "San Marino",
- timezone: "Europe/San_Marino"
- }, {
- name: "Vatican City",
- timezone: "Europe/Vatican"
- }, {
- name: "Andorra",
- timezone: "Europe/Andorra"
- }, {
- name: "Albania",
- timezone: "Europe/Tirane"
- }, {
- name: "North Macedonia",
- timezone: "Europe/Skopje"
- }, {
- name: "Bosnia and Herzegovina",
- timezone: "Europe/Sarajevo"
- }, {
- name: "Montenegro",
- timezone: "Europe/Podgorica"
- }, {
- name: "Kosovo",
- timezone: "Europe/Belgrade"
- }, {
- name: "Belarus",
- timezone: "Europe/Minsk"
- }, {
- name: "Moldova",
- timezone: "Europe/Chisinau"
- }, {
- name: "Georgia",
- timezone: "Asia/Tbilisi"
- }, {
- name: "Armenia",
- timezone: "Asia/Yerevan"
- }, {
- name: "Azerbaijan",
- timezone: "Asia/Baku"
- }, {
- name: "Kazakhstan",
- timezone: "Asia/Almaty"
- }, {
- name: "Uzbekistan",
- timezone: "Asia/Tashkent"
- }, {
- name: "Turkmenistan",
- timezone: "Asia/Ashgabat"
- }, {
- name: "Tajikistan",
- timezone: "Asia/Dushanbe"
- }, {
- name: "Kyrgyzstan",
- timezone: "Asia/Bishkek"
- }, {
- name: "Afghanistan",
- timezone: "Asia/Kabul"
- }, {
- name: "Pakistan",
- timezone: "Asia/Karachi"
- }, {
- name: "Bangladesh",
- timezone: "Asia/Dhaka"
- }, {
- name: "Nepal",
- timezone: "Asia/Kathmandu"
- }, {
- name: "Sri Lanka",
- timezone: "Asia/Colombo"
- }, {
- name: "Myanmar",
- timezone: "Asia/Yangon"
- }, {
- name: "Cambodia",
- timezone: "Asia/Phnom_Penh"
- }, {
- name: "Laos",
- timezone: "Asia/Vientiane"
- }, {
- name: "Brunei",
- timezone: "Asia/Brunei"
- }, {
- name: "Timor-Leste",
- timezone: "Asia/Dili"
- }, {
- name: "Fiji",
- timezone: "Pacific/Fiji"
- }, {
- name: "Papua New Guinea",
- timezone: "Pacific/Port_Moresby"
- }, {
- name: "Nauru",
- timezone: "Pacific/Nauru"
- }, {
- name: "Maldives",
- timezone: "Indian/Maldives"
- }];
- function updateLocalTime() {
- const now = new Date();
- const dateString = now.toLocaleDateString('en-US', {
- weekday: 'short',
- month: 'short',
- day: 'numeric'
- });
- const timeOptions = {
- hour: 'numeric',
- minute: 'numeric',
- second: showSeconds ? 'numeric' : undefined
- };
- const timeString = now.toLocaleTimeString('en-US', timeOptions);
- localDateElement.textContent = dateString;
- localTimeElement.textContent = timeString;
- }
- function updateCountryTime(countryItem, timezone) {
- const timeElement = countryItem.querySelector('.country-time span');
- const dateElement = countryItem.querySelector('.country-date');
- const timezoneElement = countryItem.querySelector('.country-timezone');
- const now = new Date();
- const timeOptions = {
- hour: 'numeric',
- minute: 'numeric',
- second: showSeconds ? 'numeric' : undefined,
- timeZone: timezone,
- hour12: true
- };
- const dateOptions = {
- weekday: 'short',
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- timeZone: timezone
- };
- const timeString = now.toLocaleTimeString('en-US', timeOptions);
- const dateString = now.toLocaleDateString('en-US', dateOptions);
- const timezoneAbbr = Intl.DateTimeFormat('en-US', {
- timeZone: timezone,
- timeZoneName: 'short'
- }).format(now).split(' ')[2];
- timeElement.textContent = timeString;
- dateElement.textContent = dateString;
- timezoneElement.textContent = timezoneAbbr;
- }
- function renderCountries(countries) {
- countriesContainer.innerHTML = '';
- countries.forEach(country => {
- const countryItem = document.createElement('div');
- countryItem.classList.add('country-item');
- const utcOffset = getUTCOffset(country.timezone);
- const population = countryPopulations[country.name] || "Population data unavailable";
- countryItem.innerHTML = `
- <div class="country-info">
- <span class="country-name">${country.name}</span>
- <div class="timezone-details">Timezone: ${country.timezone}</div>
- <div class="country-population">Population: ${population}</div>
- </div>
- <div class="country-details">
- <span class="country-date"></span>
- <div class="country-time">
- <svg class="clock-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
- <span></span>
- <div class="loading-spinner"></div>
- </div>
- <span class="country-timezone"></span>
- <span class="utc-offset">${utcOffset}</span>
- </div>
- <div class="last-updated">Last updated: ${new Date().toLocaleTimeString()}</div>
- `;
- countriesContainer.appendChild(countryItem);
- updateCountryTime(countryItem, country.timezone);
- setInterval(() => {
- updateCountryTime(countryItem, country.timezone);
- countryItem.querySelector('.last-updated').textContent = `Last updated: ${new Date().toLocaleTimeString()}`;
- }, 1000);
- });
- }
- function filterCountries(searchTerm) {
- const filteredCountries = countriesTimezones.filter(country => country.name.toLowerCase().includes(searchTerm.toLowerCase()));
- renderCountries(filteredCountries);
- }
- searchBar.addEventListener('input', event => {
- filterCountries(event.target.value);
- });
- setInterval(updateLocalTime, 1000);
- updateLocalTime();
- renderCountries(countriesTimezones);</script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement