Without resorting to a library the best option you have presently is:
const input = "2019-05-30T07:00:00.000+01:00";
const localTime = input.substring(11, 19); // assuming you want to truncate milliseconds
console.log(localTime);
The reason is that when parsing such as string using the Date
object, the offset information is applied, but then it is discarded. In other words, all of the following are equivalent:
new Date("2019-05-30T07:00:00.000+01:00")
new Date("2019-05-30T06:00:00.000Z")
new Date(1559196000000)
The only thing actually stored within the Date
object is the value 1559196000000
. Thus, no amount of manipulating the Date
object after creating it will be guaranteed to give you back the local hour as it was originally presented in the UTC+1 offset.
Libraries like Luxon and Moment deal with this by retaining the offset and/or original string in a separate internal field. The Date
object has no such field.
In the not-too-distant future, JavaScript will be able to handle this natively using the objects and functions proposed by Temporal. For now, you can parse the string manually or use a library.