I am using epoch dates to convert to javascript Date object. My server stores the date in UTC and returns epoch in the response. My code does the following to change the epoch to a Date in angular
const monthNames = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
const dt = new Date( tempModel.endDate );
tempModel.endDate = new Date( dt.getDate() + ' ' + monthNames[ dt.getMonth() ] + ' ' + dt.getFullYear() );
The problem comes when I change the timezones on my machine. In London timezone epoch sent from my server (1716246000000) shows correctly as ’21 May 2024′ but now if I change the timezone to Hawaii which is 10 hour behind me, the date displayed is ’20 May 2024′.
How do I solve this? My epoch received from the server will always be UTC, I was to convert that epoch in local date. Eg I want to say 1716246000000 in Hawaii is 21 May and not 20 May