moment().toDate() is returns the Date with the system timezone.
Is there any other way to get date object with custom timezone.
moment().tz('America/New_York').toString()
will return you date & time for New York timezone, but .toDate() returns JavaScript Date object which has no timezone information and is always displayed in system timezone.
Thanks @ellenaua . I want to create a Date object with particular timezone is it possible?
Ex.
Convert_UTCDate_To_LocalDate(utcTime: Date, localTimeZone: string) {
var utcMoment = moment(utcTime);
var localDateTime = utcMoment.tz(localTimeZone);
return new Date(localDateTime.format('lll')); //returns java script date it contains system time zone not 'localTimeZone'
}
It's impossible, JavaScript Date object does not store any timezone information (it contains unix timestamp inside, and when you call .getMinutes (), getHours (), toString () it uses system timezone). That's why moment-timezone was created: to have Date objects which also have timezone info.
Thanks for your time @ellenaua
Most helpful comment
will return you date & time for New York timezone, but .toDate() returns JavaScript Date object which has no timezone information and is always displayed in system timezone.