I have the following function to filter times.
function getFilteredTimes(time){
const newArray = time.forEach(element => {
const timeValue = moment.parseZone(element.startTime)
let now = new Date(
element.startTime,
).toLocaleTimeString([], {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'America/New_York',
})
console.log( 'timevalue', new Date(element.startTime) > new Date().toLocaleString("en-US", {
timeZone: "America/New_York"
}))
})
return time.filter(item => {
const timeValue = new Date(item.startTime); // Convert the start time to a Date object
if (moment(item.startTime).isAfter(moment())) {
return true;
}else {
return false;
}
// return timeValue > currentTime; // Keep only the times that are in the future
});
}
I tried many things. Using moment js library, using js Date() class. converting to different formate and then compare. Changing timezones.
Heres what I am getting date and times from the server
its in timezone -04:00
I am getting the current time in formate 2023-07-10T11:15:00
but server is 2023-07-10T11:15:00-04:00
How to compare this.
I wanted that only the times after the current time show not the previous ones.