I've been able to pull temperatures of a specific city using the WorldTimeAPI:
jQuery.getJSON("https://api.openweathermap.org/data/2.5/weather?q=Rome&units=metric&appid=ab85ba57bbbb423fb62bfb8201126ede", function(data) {
console.log(data);
var temp = Math.floor(data.main.temp);
jQuery(".temp").append(temp + '°C');
});
Now I'm trying to retrieve the date/time in a specific format (14 APR | 14:37)
jQuery.getJSON("http://worldtimeapi.org/api/timezone/Europe/Italy/Rome", function showDateTime() {
var myDiv = document.getElementById("date-time");
var date = new Date();
// var dayList = ["DOM", "LUN", "MAR", "MER", "GIO", "VEN", "SAB"];
var monthNames = [
"GEN",
"FEB",
"MAR",
"APR",
"MAG",
"GIU",
"LUG",
"AGO",
"SET",
"OTT",
"NOV",
"DEC"
];
var dayName = dayList[date.getDay()];
// var monthName = monthNames[date.getMonth()];
var today = `${date.getDate()} ${monthName}`;
var hour = date.getHours();
var min = date.getMinutes();
var time = hour + ":" + min;
myDiv.innerText = `${today} | ${time}`;
}
setInterval(showDateTime, 0);
It pulls the time, and it's in real time, but of my local hour, and not of Rome (location I need to point to, and that I am successfully getting via the API for the temperature.
How can I get the time/date of Rome while connecting from somewhere else? I need to always show the current time/date of Rome and not of the user visiting.
Very appreciated!