Unexpected number of hours when using Date's getHours()


I’m trying to understand why the following code assigns the value 2 to the hours.
I was expecting it to be 0:0:1 as I am just increasing the number of seconds by 1.
Instead, I am getting: 2:0:1

Any help would be appreciated

let from = new Date().getTime();
let to = from + 1000;

alert(format(to - from));

function format(timestamp) {

    let date = new Date(timestamp);

    let hours = date.getHours();
    let minutes = date.getMinutes();
    let seconds = date.getSeconds();

    return hours + ':' + minutes + ':' + seconds;

For me, I’m getting 13:0:1 because the timestamp given to the format function is 1000.

That 1000 is seen by the Date function as 1000 milliseconds from the beginning of 1970, which is one second.
I am in New Zealand which is GMT+13, which is why my hours are shown as being 13.

Thanks for the clarification.
I cannot rely on Date to format my time.
Will write this myself

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.