I am in India, and selecting time 9:00 AM, and timezone eg. ‘America/Dawson’ and I want to convert time according to selected timezone to ‘America/New_York’ timezone.But Not getting result
var currentDate = new Date()
currentDate.setHours(9, 0, 0);
moment.tz.setDefault('America/Dawson')
var currentDateMom = moment(currentDate)
var oldTimezoneTime = currentDateMom.tz('America/New_York').format('YYYY-MM-DD HH:mm:ss ZZ');
console.log(oldTimezoneTime)
3
Answers
Before access a particular timezone, you need to load it like so,
after adding use this format
Zone Add format
We can use the
moment.tz
constructor to create our moment object with the correct year, month, day, hour etc values.This will create a moment date in the
America/Dawson
timezone with the date set to the current date and time to 09:00.We can then use the
.tz()
function to convert to the new timezone (America/New_York
)Try this…