The normal behaviour of the .toLocaleTimeString()
method is to display the time in a string representation based on the local
time zone of your environment, that's why you got a different result.
And you were passing a wrong argument milliseconds
to it in:
date.toLocaleTimeString('en',milliseconds);
Actually the Date.prototype.toLocaleTimeString() method takes an options
object as a second argument, where you can specify several options including the timeZone
which specifies the desired time zone for the output.
So call it with {"timeZone": "UTC"}
to display it in UTC
, like this:
date.toLocaleTimeString('en',{"timeZone": "UTC"})
Demo:
var milliseconds = 10000;
var date = new Date(milliseconds);
console.log(date.toLocaleTimeString('en',{"timeZone": "UTC"}));
// expected result - 0:0:10 AM
// actual result - 5:30:10 AM