I am working with momentjs and converting dates to different time zones using convertedDate = moment().utcOffset(timezone).format()
. This works well but it is a str
A cleaner approach to get a native Date object with time according to the timezone, using moment
would be following:
convertedDate = moment.utc(moment.tz(timezone).format('YYYY-MM-DDTHH:mm:ss')).toDate()
PS: assuming two things
- you have imported both
'moment'
and'moment-timezone'
.- value of
timezone
is given like'Asia/Kolkata'
instead of an offset value