I have been working with a timezone API that provides the time from a specific city in this format: 2019-10-26 15:30. I want to display only the time on my page, but currently it shows the full date as well, which is not what I desire.
This is my first experience dealing with APIs and JSON. After searching and googling for solutions, I still haven't found a straightforward fix.
The fetched data displays the whole date, and I attempted to use substring to get only the time part, but it didn't work as expected. However, I am unsure if the returned data is even a string to begin with.
Here's an excerpt of my code:
let newYorkClock = document.getElementById("nyClock");
function displayTime() {
fetch("http://api.geonames.org/timezoneJSON?lat=40.7&lng=-74&username=demo")
.then(response => {
return response.json();
})
.then(data => {
var timeString = data.time;
timeString.substring(11);
newYorkClock.innerHTML = timeString;
});
}
displayTime();
I'm curious about what exactly gets returned when fetching data from an API.
Is there a way to extract or manipulate only a portion of the retrieved data from an API? If so, how can this be achieved? This is my first time asking a question rather than solely relying on Google for answers.