Skip to content

Commit

Permalink
time
Browse files Browse the repository at this point in the history
  • Loading branch information
tonmoy7722 committed Aug 25, 2024
1 parent f3df826 commit 2ce487e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ async function getWeatherData(location) {
// Get hourly forecast data
hourlyData = data.forecast.forecastday[0].hour;
currentIndex = 0; // Reset index

// Get current local time at the searched location
const localTime = data.location.localtime;

// Format the local time using toLocaleTimeString
const formattedTime = new Date(localTime).toLocaleTimeString('en-US', { hour24: true });


// Update weather info
weatherInfo.innerHTML = `
<h3>${city} (${data.location.country})</h3>
<h3>${formattedTime} - ${city} (${data.location.country})</h3>
<img id="weather-icon" src="${weatherIconUrl}" alt="${weatherConditionValue}">
<p id="temperature">Temperature: ${temperatureValue}°C</p>
<p id="weather-condition">Weather: ${weatherConditionValue}</p>
Expand Down

0 comments on commit 2ce487e

Please sign in to comment.