currently I am trying to create a function to tell me if a date event provided in a json object, is finish or not, by subtracting the current day and the end Date, however it always result positive, not sure what I am doing wrong, or if I am parsing bad the info coming from the json, still I placed the string in "hard" to see if that will change something, but still having the same issue:
So my function looks like this:
$(document).ready(function (e) {
for (let i = 0; i < eventsObject.events.length; i++) {
var startTime = new Date(eventsObject.events[i].begin).getTime();
var endTime = new Date(eventsObject.events[i].end).getTime();
var classId = "event-" + i;
var now = new Date().getTime();
var distance = endTime - now;
if (distance < 0) {
console.log("The event number " + i + " ended")
}
}
});
and my json Object looks like this:
var eventsObject = {
"events": [
{
"begin": "Mar 10, 2022 17:10:00 UTC",
"end": "Mar 10, 2022 17:13:00 UTC"
},
{
"begin": "Mar 8, 2022 17:15:00 UTC",
"end": "Mar 8, 2022 17:21:00 UTC"
},
{
"begin": "Mar 9, 2022 17:25:00 UTC",
"end": "Mar 9, 2022 17:30:00 UTC"
},
{
"begin": "Mar 10, 2022 11:00:00 UTC",
"end": "Mar 10, 2022 11:10:00 UTC"
},
]
}
So in theory just one event should be finished(08.03.2022), based in my date zone, Central Europe. Or might be this the issue maybe? Thank in advance for the help.