how to convert date without timezone?
data from the backend comes in the format
1701699255
I’m trying to execute code like this
new Date((1701699255 * 1000) - new Date().getTimezoneOffset() * 60000)
but it still gives me data in timezone format
how to do it right
2
Answers
As far as I understood your requirement; you want to convert the timestamp to a date string without timezone, for which you can use the
toISOString()
method and then remove the timezone information from the resulting string.Another approach is to use
getUTC*
methods in case you want to keep theDate
object and display it without timezone.const str = new Date().toLocaleString(‘en-US’, { timeZone: ‘Asia/Jakarta’ });
console.log(str);