I have code that fetches time differences in UTC, but it outputs straight to HTML. I want to store the results of the function to use later, such that in the example below, r1
and r2
stores the result of responseText
based on the 'timezone' passed. How can I do this?
<!-- <input type="button" value="Get Current Time" onclick="getTime()"> -->
<p id="responseText"></p>
function getTime(timezone) {
$.get("https://worldtimeapi.org/api/timezone/" + timezone, null, function(data) {
$("#responseText").text(data.raw_offset)
})
};
var r1 = getTime("Asia/Kolkata");
var r2 = getTime("Europe/Copenhagen");