I have this method below that takes in a Javascript date and then has to use Moment js to do its timezone conversion.
QUESTION - Is there a way to accomplish this without moment, just using a JS Date?
// ex. (someDate, 'America/Los_Angeles', 'MMM DD @ h:mm A z')
transform(dateUtc: Date, timeZone: string, momentFormat: string): string {
const tempDateUtc = moment(dateUtc).utc(true);
tempDateUtc.tz(timeZone);
return tempDateUtc.format(momentFormat);
}
To apply specific date formatting, rather than a locale based format, then no, not really, but it is possible to get the localized date parts to create a custom format.
As @RobG mentioned, you can use the Intl.DateTimeFormat to create a formatter. You build your options, including your timezone, and then use it's formatToParts(date) method to get the parts you need to construct your output.
Of course, this only works well if your Date is constructed using an epoch or UTC value.