Let's suppose my time in India is 9:30AM, so i want to convert this time to some other timezone of a different country.
Click here to see the image preview for this.
So, i hve this timeslots of 45 mins each of Asia/Calcuuta, and as you see someone has booked the first 2 time slots.
So, now as i as another user from Asia/Karachi try to book the time slot, first it overrides and interchanges the Asia/Calcutta time to Asia/Karachi, but the issue is that those 2 booked slots are show here as Avialable. I want that anyone from any timezone see the booked slots as well.
Click here to see the image preview for this.
for(var i=0;i<slotsArray.length;i++)
{
for(var j=0;j<this.bookedTimingsOfUser.length;j++)
{
var getStartValInSlice = (this.bookedTimingsOfUser[j][0].userstartTime).slice(0, -3);
if((momenttm(date+ " " + slotsArray[i].timeSlotStart).tz(timezone)).tz(this.bookedTimingsOfUser[j][0].userBookedTimezone).format('LT') == momenttm(date+ " " + getStartValInSlice).tz(this.bookedTimingsOfUser[j][0].userBookedTimezone).format('LT') && moment(getDate.value).format('LL') == this.bookedTimingsOfUser[j][0].userbookedDate)
slotsArray[i].timeSlotStart = "Booked";
}
}
}
How can i achive this using JS or any other time conversion npm packages like moments.js ???
You can pass timezone property to toLocaleString method to convert this time to different timezone
const timezoneSelect = document.querySelector('#timezones'),
displayZone = document.querySelector('strong');
timezoneSelect.addEventListener('change', function(e) {
const date = new Date().toLocaleTimeString('en-US', {
timeZone: this.value
});
displayZone.innerText = date;
})
<select name="timezones" id="timezones">
<option value="Asia/Kolkata">Asia/Kolkata</option>
<option value="Asia/Karachi">Asia/Karachi</option>
</select>
<p>Current Time: <strong>HH:MM:SS</strong></p>